Improve queries

feat/course
Kamran Ahmed 2 weeks ago
parent eff41bb78b
commit e07ad8cca3
  1. 2
      src/data/courses/sql-mastery/chapters/subqueries-and-ctes/lessons/books-above-average.md
  2. 3
      src/data/courses/sql-mastery/chapters/subqueries-and-ctes/lessons/latest-category-books.md
  3. 15
      src/data/courses/sql-mastery/chapters/subqueries-and-ctes/lessons/low-stock-by-category.md
  4. 2
      src/data/courses/sql-mastery/chapters/subqueries-and-ctes/lessons/new-customer-analysis.md

@ -43,7 +43,7 @@ Write a query that shows:
- Price
- How much the price is above the average (rounded to 2 decimal places)
Only include books that are priced above the average book price.
Only include books that are priced above the average book price and order by price in descending order.
## Expected Output

@ -67,6 +67,5 @@ WHERE b1.published_date = (
SELECT MAX(published_date)
FROM book b2
WHERE b2.category = b1.category
)
ORDER BY b1.category;
);
```

@ -75,18 +75,5 @@ WHERE b1.stock < (
SELECT AVG(stock)
FROM book b2
WHERE b2.category = b1.category
)
ORDER BY b1.category, b1.stock;
);
```
This challenge requires you to:
1. Use a correlated subquery to calculate the average stock for each category
2. Compare each book's stock to its category average
3. Show only books with below-average stock
The solution demonstrates:
- Using correlated subqueries in both SELECT and WHERE clauses
- Comparing individual values against group averages
- Working with a single table
---

@ -90,6 +90,8 @@ Write a query using CTEs that shows the top 3 selling books and how many new cus
- Total quantity sold
- Number of new customers who bought the book
Order by total quantity sold in descending order.
## Expected Output
| title | total_sold | new_customer_count |

Loading…
Cancel
Save