1. Window aggregate
OVER turns sum() into a window function that does not collapse rows.
sum(value) OVER (Typorithm · medium
Step 1 of 8 · intro card
Querying
Window functions use OVER (PARTITION BY ... ORDER BY ...) to compute running totals and row numbers per partition without collapsing rows like GROUP BY does.
OVER turns an aggregate like sum() into a window function that keeps every input row.
PARTITION BY splits rows into independent windows, and ORDER BY sets the order within each window.
With ORDER BY present, sum() becomes a running total and row_number() numbers rows in sequence.
OVER (...) computes per row, no collapse.
PARTITION BY resets the window per key.
ORDER BY makes sum() a running total.
SELECT
user_id,
value,
sum(value) OVER (
PARTITION BY user_id
ORDER BY ts
) AS running
FROM events;Connect each part of the code to the concept before you type.
OVER turns sum() into a window function that does not collapse rows.
sum(value) OVER (PARTITION BY restarts the calculation for each user.
PARTITION BY user_idORDER BY ts defines the running order for the cumulative sum.
ORDER BY tsEach row keeps its own running total alongside the original value.
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.