GROUP BY with ORDER BY in SQL
📖 Scenario: You work for a small bookstore. The store keeps a record of every sale in a table called sales. Each sale has the book's title, the author, and the quantity sold.The manager wants to see how many copies of each book have been sold in total, sorted from the most sold to the least sold.
🎯 Goal: Create an SQL query that groups the sales by title and author, sums the total quantity sold for each book, and orders the results by the total quantity sold in descending order.
📋 What You'll Learn
Use the
sales table with columns title, author, and quantityGroup the results by
title and authorCalculate the total quantity sold for each book using
SUM(quantity)Order the results by the total quantity sold in descending order
💡 Why This Matters
🌍 Real World
Bookstores and many businesses use GROUP BY with ORDER BY to summarize and rank sales data.
💼 Career
Understanding how to group and order data is essential for data analysis and reporting roles.
Progress0 / 4 steps