Lesson 21 / 37 · Grouping
Grouping by two keys
A group is a distinct combination of all the keys. (US, paid) and (US, refunded) are different groups. Fewer or more keys means coarser or finer groups.
The query
SELECT c.country, o.status, count(*) AS orders
FROM orders o
JOIN customers c ON c.id = o.customer_id
GROUP BY c.country, o.status
ORDER BY c.country, o.status
Try grouping by c.country alone, removing o.status from SELECT, GROUP BY and ORDER BY: the groups merge into 6, one per country.
Next: An aggregate without GROUP BY makes one group · All lessons