How GROUP BY changes query execution
📖 Scenario: You work at a small bookstore that keeps track of sales in a database table called sales. Each sale records the book_title, the genre of the book, and the quantity sold.Your manager wants to understand how many books were sold in total for each genre to decide which genres to promote.
🎯 Goal: Build a SQL query that groups sales by genre and calculates the total quantity sold for each genre using GROUP BY.
📋 What You'll Learn
Create a table called
sales with columns book_title (text), genre (text), and quantity (integer).Insert the exact sales data provided.
Write a query that groups the sales by
genre.Calculate the total quantity sold per genre using
SUM(quantity).Use
GROUP BY genre in the query.💡 Why This Matters
🌍 Real World
Grouping sales data by category helps businesses understand which product types sell best and make informed marketing decisions.
💼 Career
Data analysts and database developers often write GROUP BY queries to summarize and report data efficiently.
Progress0 / 4 steps