We use cookies for site analytics. Accept to help us understand how the site is used. See our Privacy Policy for details.
A medium sql problem, graded against 4 test cases (2 of them hidden).
Query-writing problems - joins, aggregation, window functions, and query tuning.
Reach for it when you see: A schema and a question about the data rather than a function signature.
More SQLproblems →```sql
SELECT customer_id, SUM(total) AS total_spend
FROM Orders
GROUP BY customer_id
HAVING SUM(total) > 1000
ORDER BY total_spend DESC, customer_id ASC;
```
WHERE vs HAVING - the classic interview question:
- `WHERE` runs before `GROUP BY`. It filters individual rows, can't reference aggregates.
- `HAVING` runs after `GROUP BY`. It filters groups, must reference aggregates or grouped columns.
Mixing them is fine and often correct: `WHERE order_date >= '2026-01-01' GROUP BY ... HAVING SUM(total) > 1000`.
The full reference solution in every supported language stays in the editor above - reveal it there once you have had a real attempt.
Read off this problem's own test suite, so these are the cases a submission actually has to survive.
These apply to the pattern as a whole, not just this problem.