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 3 test cases (1 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 id, customer_id, order_date, total,
SUM(total) OVER (
PARTITION BY customer_id
ORDER BY order_date, id
ROWS UNBOUNDED PRECEDING
) AS running_total
FROM Orders
ORDER BY customer_id, order_date, id;
```
ROWS vs RANGE:
- `ROWS` is positional - exactly N rows back / forward.
- `RANGE` is value-based - includes peers (rows with the same ORDER BY value).
For a running total this difference matters when ORDER BY has ties: `RANGE` will sum all peer rows together, `ROWS` won't. The interviewer might ask "what happens with two orders on the same date?" - know the answer.
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.