Rolling Sum with Missing Dates
SQL coding challenge · Difficulty: medium · Topic: Window Functions · +200 XP
Your sales database has gaps — some days have no entries at all (zero sales). The finance team needs a complete date series with no missing days, where missing days show 0, and a running cumulative total.
Return: date, sales (0 if missing), running_total
Sort by date ascending.
Hint: You will need to generate all dates between the min and max date in the table.
Example input
| sale_date | sales | | --- | --- | | 2024-01-01 | 100 | | 2024-01-02 | 200 | | 2024-01-05 | 150 | | 2024-01-06 | 300 | | 2024-01-07 | 250 | | 2024-01-09 | 400 |
Expected output
`
2024-01-01 | 100 | 100
2024-01-02 | 200 | 300
2024-01-05 | 150 | 450
2024-01-06 | 300 | 650
2024-01-07 | 250 | 700
2024-01-09 | 400 | 950
`
What this SQL challenge teaches you
“Rolling Sum with Missing Dates” is a medium-level SQL challenge focused on Window Functions. Working through it gives you hands-on practice with Window Functions — the kind of transformation you are asked to write in real data engineering work and in technical interviews. You can solve it directly in the browser: the dataset is pre-loaded, so you write the query or DataFrame code, run it, and compare your output against the expected result immediately.
How to approach it
If you get stuck, work through these steps in order before looking at a full solution — each one narrows the problem down:
- Your result should return: date, sales (0 if missing), running_total.
- Order the output date ascending.
- You will need to generate all dates between the min and max date in the table
- Compare your output to the Expected Output — the columns, values and row order must match exactly.
Where this comes up
Variations of this problem have been reported in interviews at Amazon. Interviewers use it to check whether you can express the logic cleanly and reason about correctness on edge cases such as ties, nulls and empty groups.
How to practise it on PySpark.in
Open the challenge, write your SQL query in the editor and press Run to execute it against the sample dataset. Submitting checks your output against every test case, including hidden ones, so you find out straight away whether your logic holds up. You can retry as often as you like, and each solved challenge adds to your XP.
Related SQL challenges
- Top 3 Products per Category
- Running Total Revenue
- Median Salary per Department
- Latest Order Per Customer
- 3-Day Rolling Sum of Sales
- 7-Day Rolling Purchase Amount by Customer
Frequently asked questions
Do I need to install Spark or a database to solve this?
No. The SQL environment runs in your browser with the sample data already loaded, so there is nothing to install or configure.
Is this challenge free?
Yes - the problem, the sample dataset, the hints and unlimited test runs are free.
What level is it?
It is rated medium and covers Window Functions.