Easy
SQL-W02sqlRunning Total Per User
Problem
Given `txns(user_id, ts, amount)`, output (user_id, ts, amount, running_total) where running_total is the cumulative sum **per user** ordered by ts.
Input
Transactions ordered by ts.
Output
user_id, ts, amount, running_total
Constraints
1 ≤ rows ≤ 10^6
Sample input
(1,'2024-01-01',10),(1,'2024-01-02',5),(2,'2024-01-01',7)
Sample output
1,2024-01-01,10,10 1,2024-01-02,5,15 2,2024-01-01,7,7
Explanation
PARTITION BY user_id resets the window per user.
window-fnrunning-sumpartition-by@Stripe
Visible test cases
in: see
out: rows
Your solution — run it, use AI if stuck
sql
