Skip to main content
Calculates the relative rank of the current row within an ordered data set, as ( rank - 1 ) / ( rows - 1 ) where rank is the current row’s rank within the partition, and rows is the number of rows in the partition. PERCENT_RANK always returns values from 0 to 1 inclusive. The first row in any set has a PERCENT_RANK of 0.

Syntax

Parameters

Return Type

DOUBLE PRECISION This function respects NULL values, and results will be ordered with default null ordering NULLS LAST unless otherwise specified in the ORDER BY clause.

Example

The example below calculates the relative rank of each player’s score within their level. The highest score has a PERCENT_RANK of 0, and the lowest has 1.

Rows: 4Execution time: 3.04ms