SQL Server Window Functions

This page lists the commonly used window functions in SQL Server.

  1. DENSE_RANK

    In SQL Server, the DENSE_RANK() function is a ranking function that assigns a rank value to each row in a query result set.
  2. FIRST_VALUE

    The FIRST_VALUE() function is a window function that returns the first value from a window.
  3. LAG

    The SQL Server LAG() function is a window function that can be used to access the previous row of data in a query result set.
  4. LAST_VALUE

    The LAST_VALUE() function is a window function in SQL Server used to retrieve the last value in a group.
  5. LEAD

    The LEAD() function is a window function in SQL Server that retrieves data from the row after the current row.
  6. NTILE

    In SQL Server, the NTILE() function can divide a result set into a specified number of buckets and assign each row to one of the buckets.
  7. PERCENTILE_CONT

    In SQL Server, the PERCENTILE_CONT() function is a statistical function used to calculate the value corresponding to a specified percentile.
  8. PERCENTILE_DISC

    PERCENTILE_DISC() is an aggregate function in SQL Server used to calculate the specified percentile of a set of values.
  9. RANK

    In SQL, the RANK() function is used to assign ranks to rows in a result set based on specified sort criteria in ascending or descending order.
  10. ROW_NUMBER

    ROW_NUMBER() is a window function used to assign a unique row number to each row in a result set.