A data analyst needs to count the number of orders placed by each customer, but only for customers who have placed more than 5 orders. Which SQL clause should be used to filter the aggregated results?
HAVING filters groups after aggregation, so it can test COUNT(*) > 5 per customer. WHERE cannot reference aggregate functions, making HAVING the clause that satisfies the requirement to restrict results to customers exceeding five orders.
Why this answer
HAVING is used to filter groups after aggregation. The query would use GROUP BY customer_id, then HAVING COUNT(*) > 5.