SQL HAVING
Filter groups after aggregation.
Syntax
GROUP BY col HAVING condition_on_aggregates
WHERE filters rows before grouping; HAVING filters the groups afterwards.
Example
Query (on the shop database used in the SQL course)
SELECT country, COUNT(*) AS customers FROM customers GROUP BY country HAVING COUNT(*) >= 3;
Result
| country | customers |
|---|---|
| Australia | 12 |
| Nepal | 4 |
| United Kingdom | 3 |
3 rows
Related
Learn it step by step in the free lesson Summarising Data, with exercises that check your queries.