HAVING filters the grouped results by their totals. Where WHERE runs before grouping and looks at individual rows, HAVING runs after grouping and looks at each group’s aggregated metrics.
HAVING uses the same operators and AND / OR logic as WHERE, so you can combine conditions.
HAVING needs a GROUP BY. To cap how many groups you keep once they are filtered and sorted, add ORDER BY and LIMIT.
