Running total of revenue by month
The CFO wants a cumulative revenue line for the year. Revenue counts only orders that were not cancelled, and a line's revenue is quantity × price.
Task: return each month (YYYY-MM), that month's revenue and the running total up to and including that month (both rounded to 2 decimals), in month order.
The data you can query
Each table is shown with its column types and the first rows, so you can see exactly what the data looks like.
| id INTEGER | name TEXT | city TEXT | signup_date TEXT |
|---|---|---|---|
| 1 | Ayesha Khan | Lahore | 2025-11-03 |
| 2 | Bilal Ahmed | Karachi | 2025-11-12 |
| 3 | Hina Malik | Islamabad | 2025-12-01 |
| 4 | Usman Tariq | Rawalpindi | 2025-12-15 |
| 5 | Sana Iqbal | Lahore | 2026-01-04 |
| 6 | Omar Farooq | Faisalabad | 2026-01-20 |
Showing the first 6 of 14 rows.
| id INTEGER | order_id INTEGER | product_id INTEGER | quantity INTEGER |
|---|---|---|---|
| 1 | 1 | 1 | 2 |
| 2 | 1 | 2 | 4 |
| 3 | 2 | 6 | 1 |
| 4 | 2 | 2 | 4 |
| 5 | 2 | 10 | 4 |
| 6 | 3 | 9 | 1 |
Showing the first 6 of 80 rows.
| id INTEGER | customer_id INTEGER | order_date TEXT | status TEXT |
|---|---|---|---|
| 1 | 3 | 2026-01-16 | Delivered |
| 2 | 11 | 2026-06-14 | Delivered |
| 3 | 7 | 2026-02-15 | Delivered |
| 4 | 10 | 2026-06-19 | Delivered |
| 5 | 5 | 2026-01-06 | Delivered |
| 6 | 9 | 2026-03-06 | Delivered |
Showing the first 6 of 40 rows.
| id INTEGER | name TEXT | category TEXT | price REAL |
|---|---|---|---|
| 1 | Wireless Mouse | Electronics | 1850 |
| 2 | USB Cable | Electronics | 450 |
| 3 | Bluetooth Speaker | Electronics | 4200 |
| 4 | Notebook A4 | Stationery | 220 |
| 5 | Gel Pen Pack | Stationery | 180 |
| 6 | Desk Organizer | Stationery | 950 |
Showing the first 6 of 10 rows.
Your query runs on SQLite. Write a single SELECT; use LIMIT instead of TOP.
Need a hint?
Compute monthly revenue in a CTE, then use SUM(revenue) OVER (ORDER BY month).
Log in or create a free account to run your code, submit and earn points.
Run your code to see the output here. Ctrl + Enter also runs it.
