GROUP BY + HAVING
Filter groups after aggregation
SQL drill • Aggregations
orders(customer_id, product_id, qty). List customer_id values that bought more than 3 distinct products (use COUNT(DISTINCT product_id)).
Reinforces GROUP BY + aggregates — the same muscle as the JOIN+GROUP bar, without a join in this toy schema.
WHERE vs HAVING
WHERE = rows · HAVING = groups
WHERE = rows · HAVING = groups
Step 0/5Line —
WHERE filters before GROUP BY — HAVING filters group summaries after.
Conceptual evaluation
Press Step or Play.
Ready
HAVING is like WHERE for aggregates — it runs after GROUP BY.