PERCENT_RANK is a window (analytic) function specified in the SELECT list or ORDER BY clause. It calculates the percentage rank of the current row compared to other rows in the same partition, using the formula (rank - 1) / (total_rows_in_partition - 1). The first row in each partition always returns 0, and the last row returns 1 when at least two rows exist. If the partition contains only one row, PERCENT_RANK returns 0 to avoid division by zero. Ties receive the same rank, so rows with identical sort keys share the same PERCENT_RANK value. The function operates after the WHERE, GROUP BY, and HAVING phases and before the final ORDER BY, making it ideal for analytic reporting without altering result cardinality.
RANK, DENSE_RANK, ROW_NUMBER, CUME_DIST, NTILE, ORDER BY, OVER clause
SQL:2003 analytic extensions
It returns a decimal between 0 and 1 indicating the row's relative position within its partition.
The function uses (rank - 1) divided by (total_rows_in_partition - 1).
Use PERCENT_RANK when you need a normalized value that is independent of partition size, enabling easy comparisons across groups.
Yes, wrap it in a subquery or CTE first, then filter on the computed column.