Skip to main content

PERCENT_RANK() (SQL)

A window function that assigns a ranking as a fractional number between 0 and 1 (inclusive) to each row within the same window frame.

Synopsis

PERCENT_RANK()

Description

PERCENT_RANK assigns a percentile ranking between 0 and 1 (inclusive) to each row. Percentile rankings indicate the percentage of data that are at or below a certain value within a group. These ranks can include duplicate values if multiple rows contain the same value for the window function field.

Examples

The following example calculates the percentile rank of each employee based on their salary within each department:

SELECT PERCENT_RANK() OVER (PARTITION BY Department ORDER BY Salary) FROM Company.Employee

See Also

FeedbackOpens in a new tab