SQL Server Window Functions

SQL Server Window Functions calculate an aggregate value based on a group of rows and return multiple rows for each group.

NameDescription
CUME_DISTCalculate the cumulative distribution of a value in a set of values
DENSE_RANKAssign a rank value to each row within a partition of a result, with no gaps in rank values.
FIRST_VALUEGet the value of the first row in an ordered partition of a result set.
LAGProvide access to a row at a given physical offset that comes before the current row.
LAST_VALUEGet the value of the last row in an ordered partition of a result set.
LEADProvide access to a row at a given physical offset that follows the current row.
NTILEDistribute rows of an ordered partition into a number of groups or buckets
PERCENT_RANKCalculate the percent rank of a value in a set of values.
RANKAssign a rank value to each row within a partition of a result set
ROW_NUMBERAssign a unique sequential integer to rows within a partition of a result set, the first row starts from 1.