From e07ad8cca39f169017a22c554a1afcaa172b2f41 Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Tue, 7 Jan 2025 21:40:36 +0000 Subject: [PATCH] Improve queries --- .../lessons/books-above-average.md | 2 +- .../lessons/latest-category-books.md | 3 +-- .../lessons/low-stock-by-category.md | 17 ++--------------- .../lessons/new-customer-analysis.md | 2 ++ 4 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/data/courses/sql-mastery/chapters/subqueries-and-ctes/lessons/books-above-average.md b/src/data/courses/sql-mastery/chapters/subqueries-and-ctes/lessons/books-above-average.md index d15005bf3..0bdc69a39 100644 --- a/src/data/courses/sql-mastery/chapters/subqueries-and-ctes/lessons/books-above-average.md +++ b/src/data/courses/sql-mastery/chapters/subqueries-and-ctes/lessons/books-above-average.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 diff --git a/src/data/courses/sql-mastery/chapters/subqueries-and-ctes/lessons/latest-category-books.md b/src/data/courses/sql-mastery/chapters/subqueries-and-ctes/lessons/latest-category-books.md index c88f51e3c..2a7f3a33b 100644 --- a/src/data/courses/sql-mastery/chapters/subqueries-and-ctes/lessons/latest-category-books.md +++ b/src/data/courses/sql-mastery/chapters/subqueries-and-ctes/lessons/latest-category-books.md @@ -67,6 +67,5 @@ WHERE b1.published_date = ( SELECT MAX(published_date) FROM book b2 WHERE b2.category = b1.category -) -ORDER BY b1.category; +); ``` \ No newline at end of file diff --git a/src/data/courses/sql-mastery/chapters/subqueries-and-ctes/lessons/low-stock-by-category.md b/src/data/courses/sql-mastery/chapters/subqueries-and-ctes/lessons/low-stock-by-category.md index 5b3990899..3469ffa39 100644 --- a/src/data/courses/sql-mastery/chapters/subqueries-and-ctes/lessons/low-stock-by-category.md +++ b/src/data/courses/sql-mastery/chapters/subqueries-and-ctes/lessons/low-stock-by-category.md @@ -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 - ---- \ No newline at end of file +); +``` \ No newline at end of file diff --git a/src/data/courses/sql-mastery/chapters/subqueries-and-ctes/lessons/new-customer-analysis.md b/src/data/courses/sql-mastery/chapters/subqueries-and-ctes/lessons/new-customer-analysis.md index 44e235109..0e93067f1 100644 --- a/src/data/courses/sql-mastery/chapters/subqueries-and-ctes/lessons/new-customer-analysis.md +++ b/src/data/courses/sql-mastery/chapters/subqueries-and-ctes/lessons/new-customer-analysis.md @@ -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 |