Window function
Also called: Analytic function, OVER clause
A SQL function computed over a set of related rows with OVER, keeping every row in the result.
Definition
PARTITION BY splits rows into groups and ORDER BY orders them inside each group, without collapsing them like GROUP BY. Aggregates become per-group totals or running totals; ranking functions (row_number, rank, dense_rank) number rows; lag and lead read neighboring rows. Window functions run after WHERE and GROUP BY, so filtering on them needs a subquery or CTE.
In practice
row_number() OVER (PARTITION BY category ORDER BY units DESC) numbers products within each category for a top-3 list.
Learn it in context
Lessons that use this term.