GROUP BY Multiple Columns in SQL
📖 Scenario: You work for a small bookstore that wants to analyze its sales data. The store keeps records of each sale, including the book title, the genre, and the number of copies sold. Your manager wants to see how many copies were sold for each combination of book title and genre.
🎯 Goal: Create an SQL query that groups sales data by both book_title and genre columns, and calculates the total copies sold for each group.
📋 What You'll Learn
Create a table called
sales with columns book_title (text), genre (text), and copies_sold (integer).Insert the exact sales data provided into the
sales table.Write a query that groups the data by
book_title and genre.Calculate the sum of
copies_sold for each group.💡 Why This Matters
🌍 Real World
Grouping sales data by multiple columns helps businesses understand combined effects, like how many copies of each book in each genre sold.
💼 Career
SQL GROUP BY with multiple columns is a common skill for data analysts and database developers to summarize and report data effectively.
Progress0 / 4 steps