Why aggregation matters
📖 Scenario: You work at a small bookstore. You have a list of sales transactions, and you want to find out how many books were sold in total and the average price of books sold. This helps you understand your business better.
🎯 Goal: Build a simple database query that uses aggregation functions to calculate the total number of books sold and the average price of the books sold.
📋 What You'll Learn
Create a table called
sales with columns book_title (text) and price (numeric).Insert exactly these rows into
sales: ('The Alchemist', 10.99), ('1984', 8.99), ('The Alchemist', 10.99), ('Brave New World', 9.99).Create a variable
min_price set to 9.00 to filter books sold at or above this price.Write a query that selects the total count of books sold and the average price of books sold where the price is greater than or equal to
min_price.Add a final statement to order the results by average price descending (even if only one row).
💡 Why This Matters
🌍 Real World
Aggregation helps businesses summarize large amounts of data quickly, like counting total sales or finding average prices.
💼 Career
Database aggregation queries are essential skills for data analysts, business intelligence professionals, and backend developers.
Progress0 / 4 steps