← Databases & SQL
13 / 25
Lesson 13 — GROUP BY
GROUP BY: one result per group
GROUP BY column splits rows into groups that share a value, and aggregates (COUNT, SUM, AVG…) are computed per group. Every column in SELECT must either be in GROUP BY or inside an aggregate.
SELECT city, COUNT(*) FROM customers GROUP BY city
Why it matters: "sales per month", "users per country", "errors per page" — GROUP BY turns raw rows into a report.
Want it another way?
Task
Write a query returning each category with its total amount, sorted by category. Expected: food 45.0, rent 500.0, travel 120.0.
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
Test your knowledge
A quick 3-question quiz on this lesson — instant feedback.