IntermediateWHERE & Filtering
Find customers with more than 3 orders
The query
SQL
SELECT cust_id, COUNT(*) AS order_count
FROM orders
GROUP BY cust_id
HAVING COUNT(*) > 3
ORDER BY order_count DESC;Note
“HAVING on aggregates is the correct approach. Never use WHERE for aggregate conditions.