You are auditing a legacy system where the transaction_id was lost during a database migration. All you have is the user, the amount, and the time.
Calculate a running total of purchase amounts for each user, ordered by time.
Because there is no primary key, multiple transactions from the same user might have the exact same timestamp. Your query must treat these as separate entries and update the running total for each row individually, rather than jumping the total all at once.
| user_id(INTEGER) | amount(DECIMAL) | transaction_time(TIMESTAMP) |
|---|---|---|
| 1 | 100 | 2026-01-01 10:00:00 |
| 1 | 50 | 2026-01-01 11:00:00 |
| 1 | 25 | 2026-01-01 11:00:00 |
| 2 | 200 | 2026-01-01 10:00:00 |
| user_id(INTEGER) | amount(DECIMAL) | transaction_time(TIMESTAMP) | running_total(DECIMAL) |
|---|---|---|---|
| 1 | 100 | 2026-01-01 10:00:00 | 100 |
| 1 | 50 | 2026-01-01 11:00:00 | 150 |
| 1 | 25 | 2026-01-01 11:00:00 | 175 |
| 2 | 200 | 2026-01-01 10:00:00 | 200 |