Last Updated: May 3, 2026
Aggregate functions like COUNT, SUM, and AVG are useful on their own, but they collapse an entire table into a single row. What if you need the count per country, or the average payment per subscription tier?
That's where GROUP BY comes in. It splits rows into groups and runs the aggregate separately on each one. HAVING then lets you filter those groups, something WHERE can't do.