MSSQL Window Functions
12 functions
ROW_NUMBERROW_NUMBER() OVER (w)Assigns a unique sequential integer to each row within a partition.
RANKRANK() OVER (w)Assigns the same rank to equal values, with gaps in ranking.
DENSE_RANKDENSE_RANK() OVER (w)Assigns the same rank to equal values, without gaps in ranking.
PERCENT_RANKPERCENT_RANK() OVER (w)Returns the relative rank as a value between 0 and 1.
CUME_DISTCUME_DIST() OVER (w)Returns the cumulative distribution value.
NTILENTILE(n) OVER (w)Divides the partition into n equal buckets.
LAGLAG(expr [, n [, default]]) OVER (w)Returns the value from n rows before the current row.
LEADLEAD(expr [, n [, default]]) OVER (w)Returns the value from n rows after the current row.
FIRST_VALUEFIRST_VALUE(expr) OVER (w)Returns the first value in the window frame.
LAST_VALUELAST_VALUE(expr) OVER (w)Returns the last value in the window frame.
PERCENTILE_CONTPERCENTILE_CONT(p) WITHIN GROUP (ORDER BY ...)Returns a percentile based on a continuous distribution.
PERCENTILE_DISCPERCENTILE_DISC(p) WITHIN GROUP (ORDER BY ...)Returns a percentile based on a discrete distribution.
