Group rows together
COUNT, MAX, and friends get more useful once you can run them per-group
instead of over the whole table. GROUP BY column buckets the rows by every
distinct value in that column, then applies the aggregate to each bucket
separately - one output row per group.
"How many users per country" is a classic GROUP BY: without it you'd get one
number for everyone; with it you get one number for each country. Any column
you SELECT alongside an aggregate has to be the column (or one of the
columns) you're grouping by - otherwise SQL doesn't know which row's value to
show.
Same six-row users table as last lesson.
Your task: return each country and how many users are from it, as total.
You'll practice:
- Grouping rows with
GROUP BY
- Combining a plain column with an aggregate in the same
SELECT