1. Window aggregate
sum(amount) OVER computes a sum across a window of rows without collapsing them into one.
sum(amount) OVERTyporithm · medium
Step 1 of 8 · intro card
Spark SQL
Window functions like sum(amount) OVER (PARTITION BY user_id ORDER BY ts) compute running totals and rankings per group without collapsing the original rows.
A window function attaches an aggregate to every row instead of replacing the group with one row.
PARTITION BY defines independent groups; ORDER BY inside the window turns the aggregate into a cumulative, per-row running value.
Swap sum for row_number, rank, or lag to number, rank, or look back across the same window.
OVER (...) keeps every input row.
PARTITION BY scopes the window per group.
ORDER BY makes the aggregate cumulative.
SELECT user_id, amount, sum(amount) OVER (PARTITION BY user_id ORDER BY ts) AS running FROM txConnect each part of the code to the concept before you type.
sum(amount) OVER computes a sum across a window of rows without collapsing them into one.
sum(amount) OVERPARTITION BY user_id restarts the window for each user, so totals do not leak across users.
PARTITION BY user_idORDER BY ts makes the sum cumulative in time order — a running total up to each row.
ORDER BY tsAS running names the windowed result column on each preserved row.
AS runningRead the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.