Filtering Grouped Data Using HAVING Clause
📖 Scenario: You are managing a small bookstore's sales database. You want to find which books have sold more than a certain number of copies to decide which books to promote.
🎯 Goal: Build an SQL query that groups sales by book title and filters groups using the HAVING clause to show only books with total sales above a threshold.
📋 What You'll Learn
Create a table called
sales with columns book_title (text) and copies_sold (integer).Insert the exact sales data provided into the
sales table.Write a query that groups sales by
book_title and sums copies_sold.Add a
HAVING clause to filter groups where total copies sold is greater than 100.💡 Why This Matters
🌍 Real World
Filtering grouped data is common in sales reports, inventory management, and any scenario where you want to analyze summarized data and apply conditions on those summaries.
💼 Career
Knowing how to use GROUP BY with HAVING is essential for data analysts, database administrators, and backend developers who work with databases to generate meaningful reports.
Progress0 / 4 steps