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 d.day::date AS date, p.id AS product_id, p.name AS product_name,
COALESCE(SUM(s.qty), 0) AS qty
FROM generate_series('2026-01-01'::date, '2026-01-31', '1 day') d(day)
CROSS JOIN Products p
LEFT JOIN Sales s ON s.product_id = p.id AND s.sale_date = d.day
GROUP BY d.day, p.id, p.name
ORDER BY d.day, p.id;
```
The CROSS JOIN guarantees every (date, product) pair exists; the LEFT JOIN to Sales lets days with no sale show 0 instead of being missing entirely. This pattern is essential for charts and time-series reports - without it, a day with zero sales just doesn't appear.
Performance: CROSS JOIN explodes row count multiplicatively. Always bound the date range and products explicitly.
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.