OVER() computes across related rows without collapsing them — ranks, running totals, lag.
Compute something across a group of rows without collapsing them — a running total, a rank, a comparison to the previous row — while keeping every row.
It's the single biggest step up in SQL skill, and it turns queries that needed self-joins into one clean line.
A window function computes a value across a set of rows related to the current row — defined by OVER(PARTITION BY … ORDER BY …) — while keeping every input row in the output. Unlike GROUP BY, it doesn't collapse rows. It powers ranking (ROW_NUMBER, RANK), running and moving aggregates (SUM/AVG OVER), and row-to-row access (LAG, LEAD).
Window functions run an aggregate over a 'window' of rows defined by OVER(), without collapsing the result the way GROUP BY does. PARTITION BY groups the window, ORDER BY sequences it. Use them for ROW_NUMBER/RANK, running totals, moving averages, and LAG/LEAD comparisons — every row survives, enriched with a new column.
Intermediate SQL Tutorial | Partition By — Alex The Analyst, 4:14