GROUP BY with aggregate functions
📖 Scenario: You are managing a small bookstore database. You want to find out how many books are available in each genre and the average price of books in each genre.
🎯 Goal: Build a SQL query that groups books by their genre and calculates the total number of books and the average price for each genre.
📋 What You'll Learn
Create a table called
books with columns id, title, genre, and price.Insert the exact data rows provided into the
books table.Write a SQL query that groups the books by
genre.Use aggregate functions
COUNT() and AVG() to find the number of books and average price per genre.💡 Why This Matters
🌍 Real World
Grouping and summarizing data is common in business reports, like sales by category or average ratings by product type.
💼 Career
Database analysts and developers often write GROUP BY queries with aggregate functions to generate insights from data.
Progress0 / 4 steps