GROUP BY
Applies to: sql
GROUP BY collapses rows that share a value into one row per group, so you can compute an aggregate (count,
sum, average) per group. HAVING filters the groups after aggregation.
SELECT user_id, COUNT(*) AS orders
FROM orders
GROUP BY user_id
HAVING COUNT(*) > 5;
See also: aggregate-function, select