Concept
Window Function
Function that computes a value over a window of related rows defined by an OVER clause, without collapsing rows like a GROUP BY.
A window function is invoked with an OVER (...) clause. The clause defines a partition (a peer group of rows) and an order within that partition; the function then computes a value for each row using its peers as context, but every input row stays in the result.
Common window functions include ROW_NUMBER, RANK, DENSE_RANK, LAG, LEAD, SUM, AVG, and NTILE. They are the cleanest way to write running totals, ranks within groups, top-N-per-group queries, and period-over-period comparisons.
Because they are evaluated after WHERE and GROUP BY but before ORDER BY of the outer query, you typically need a subquery or CTE to filter on a window result.