Monthly Sales with Running Total
Preview mode. Log in to edit, run, submit, and save progress.
Monthly Sales with Running Total
You are given a table of sales records. Each record has an id, a sale date, and an amount. Write a SQL query to return for each calendar month: the total sales amount for that month (monthly_total), and the cumulative running total of all sales up to and including that month (running_total). Return the result ordered by month ascending. Table: Sales
| Column Name | Type | Description |
|---|---|---|
| id | INT | Primary key |
| sale_date | DATE | Date of the sale |
| amount | DECIMAL | Sale amount |
Examples
January has two sales totalling 800. February has two totalling 900; running total becomes 1700. March has 900; running total becomes 2600.
Approach hint
Start with a simple approach, explain the trade-off, then move toward a cleaner or more scalable solution.
Common mistake
Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.