MySQL tutorial: PERCENT_RANK [EN]
top of page
CerebroSQL

MySQL: 

PERCENT_RANK

PERCENT_RANK() over_clause

Returns the percentage of partition values less than the value in the
current row, excluding the highest value. Return values range from 0 to
1 and represent the row relative rank, calculated as the result of this
formula, where rank is the row rank and rows is the number of partition
rows:

(rank - 1) / (rows - 1)

This function should be used with ORDER BY to sort partition rows into
the desired order. Without ORDER BY, all rows are peers.

over_clause is as described in
https://dev.mysql.com/doc/refman/8.0/en/window-functions-usage.html.

For an example, see the CUME_DIST() function description.

URL: https://dev.mysql.com/doc/refman/8.0/en/window-function-descriptions.html

Example

bottom of page