List of MySQL Window Functions

Below is a list of functions that can be used as window functions in MySQL.

Some are nonaggregate functions that can only be used as window functions, while others are aggregate functions that can be used as window functions if required.

Nonaggregate Window Functions

The following functions are nonaggregate functions that can only be used as window functions. These require an OVER clause, which specifies how to partition query rows into groups for processing by the window function.

NameDescription
CUME_DIST()Returns the cumulative distribution of a value within a group of values.
DENSE_RANK()Returns the rank of the current row within its partition, without gaps.
FIRST_VALUE()Returns the value of the given expression from the first row of the window frame.
LAG()Returns the value of a given expression from the row that lags (precedes) the current row by a given number of rows within its partition.
LAST_VALUE()Returns the value of the given expression from the last row of the window frame.
LEAD()Returns the value of a given expression from the row that leads (follows) the current row by a given number of rows within its partition.
NTH_VALUE()Returns the value of argument from N-th row of the window frame.
NTILE()Returns the bucket number of the current row within its partition.
PERCENT_RANK()Returns the percentage of partition values less than the value in the current row, excluding the highest value.
RANK()Returns the rank of the current row within its partition, with gaps.
ROW_NUMBER()Returns the number of the current row within its partition.

Aggregate Window Functions

Below are MySQL aggregate functions that can be used as window functions. These functions can be used with or without an OVER clause. When used with the OVER clause, they become window functions.

NameDescription
AVG()Returns the average value of its argument.
BIT_AND()Returns the bitwise AND.
BIT_OR()Returns the bitwise OR.
BIT_XOR()Returns the bitwise XOR.
COUNT()Returns a count of the number of rows to be returned by a query.
JSON_ARRAYAGG()Returns the result set as a single JSON array.
JSON_OBJECTAGG()Returns the result set as a single JSON object.
MAX()Returns the maximum value.
MIN()Returns the minimum value.
STD()Returns the population standard deviation.
STDDEV()Returns the population standard deviation.
STDDEV_POP()Returns the population standard deviation.
STDDEV_SAMP()Returns the sample standard deviation.
SUM()Returns the sum.
VAR_POP()Returns the population standard variance.
VAR_SAMP()Returns the sample variance.
VARIANCE()Returns the population standard variance.