Explore Library
Code Quiz

Filtering Aggregated Order Counts

Spot the mistake in a JOIN query that groups customers and filters by their order count.

Codesql
SELECT c.customer_id,
       c.name,
       COUNT(o.order_id) AS order_count
FROM customers c
JOIN orders o ON o.customer_id = c.customer_id
WHERE COUNT(o.order_id) > 5
GROUP BY c.customer_id, c.name
ORDER BY order_count DESC;

What is the bug in this query, and how should it be fixed?