SQL interview question: running revenue total by city
Problem
Shared data rulesFor each city, compute daily revenue for Sep 1–27, 2026 and a running total from the start of the month.
Example
orders| order_id | created_at | status | city | amount_usd |
|---|---|---|---|---|
| 201 | 2026-09-01 10:40 | delivered | Boston | 30 |
| 202 | 2026-09-01 12:15 | delivered | Boston | 46 |
| 203 | 2026-09-02 11:10 | delivered | Boston | 16 |
| 204 | 2026-09-02 14:00 | delivered | New York | 62 |
| 205 | 2026-09-03 19:30 | delivered | Boston | 24 |
| city | order_date | day_revenue | cumulative_revenue |
|---|---|---|---|
| Boston | 2026-09-01 | 76 | 76 |
| Boston | 2026-09-02 | 16 | 92 |
| Boston | 2026-09-03 | 24 | 116 |
| New York | 2026-09-02 | 62 | 62 |
Boston: $76 on Sep 1, then $76 + $16 = $92 and $92 + $24 = $116. New York has its own total — $62.
Solve it free
Your query runs on PostgreSQL in your browser. No sign-up needed.