Apply conditions after aggregation.
Section: Aggregation and Grouping
Filter groups with HAVING
sql
sql
SELECT customer_id, COUNT(*) AS order_count
FROM orders
GROUP BY customer_id
HAVING COUNT(*) >= 5;Explanation
WHERE filters rows before grouping; HAVING filters grouped results.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Aggregation and Grouping