Running total of payments
Mediumsqlwindow functions
For each payment return paid_on, amount and running_total = the sum of all payments up to and including this one (ordered by paid_on, then id). Return rows in that same order.
Tables
- payments (id INTEGER, paid_on TEXT, amount INTEGER)
Example 1
payments
| id | paid_on | amount |
|---|---|---|
| 1 | 2026-01-03 | 100 |
| 2 | 2026-01-01 | 50 |
| 3 | 2026-01-03 | 25 |
Expected result
| paid_on | amount | running_total |
|---|---|---|
| 2026-01-01 | 50 | 50 |
| 2026-01-03 | 100 | 150 |
| 2026-01-03 | 25 | 175 |
Constraints
- 0 ≤ rows ≤ 1000
- paid_on is YYYY-MM-DD
- The order of rows matters
Submit checks your solution against 7 tests, including hidden ones.
SQL
-- Write one SELECT query. Tables: payments SELECT