Window Functions API Reference
SQL window functions for computations across rows related to the current row.
Window Functions
Functions that operate over a 'window' of rows defined by an OVER clause.
ROW_NUMBER() OVER (PARTITION BY ... ORDER BY ...)Assign a unique sequential integer to each row within a partition.
Returns: bigint
RANK() OVER (PARTITION BY ... ORDER BY ...)Assign a rank with gaps. Ties get the same rank; next rank skips.
Returns: bigint
DENSE_RANK() OVER (PARTITION BY ... ORDER BY ...)Assign a rank without gaps. Ties get the same rank; next rank is consecutive.
Returns: bigint
LAG(expr, offset, default) OVER (PARTITION BY ... ORDER BY ...)Return the value of expr from a row that is offset rows before the current row.
Returns: any
LEAD(expr, offset, default) OVER (PARTITION BY ... ORDER BY ...)Return the value of expr from a row that is offset rows after the current row.
Returns: any
NTILE(n) OVER (PARTITION BY ... ORDER BY ...)Distribute rows into n approximately equal groups, returning the group number (1..n).
Returns: int
SUM(expr) OVER (PARTITION BY ... ORDER BY ...)Running or partitioned sum. Without ORDER BY, returns the partition total per row.
Returns: numeric
AVG(expr) OVER (PARTITION BY ... ORDER BY ...)Running or partitioned average. With ORDER BY and a frame, computes a moving average.
Returns: numeric