Skip to content

PERCENT_RANK

PERCENT_RANK() OVER ([PARTITION BY partition_expression] ORDER BY sort_expression [ASC | DESC])

Section titled “PERCENT_RANK() OVER ([PARTITION BY partition_expression] ORDER BY sort_expression [ASC | DESC])”
CREATE TABLE Students (
student_name varchar(30),
score int
);
INSERT INTO Students
VALUES('Alex', 90), ('Ben', 85), ('Catherine', 92), ('Daniel', 80), ('Emma', 89);
SELECT student_name, score,
PERCENT_RANK() OVER(ORDER BY score)
FROM Students;
| student_name | score | percent_rank |
|--------------|-------|--------------|
| Daniel | 80 | 0 |
| Ben | 85 | 0.25 |
| Emma | 89 | 0.5 |
| Alex | 90 | 0.75 |
| Catherine | 92 | 1 |

In the given example, PERCENT_RANK function is applied on the score column in the Students table. The function calculates the percentile rank for each student’s score. The percentile rank is a percentile score that ranges from 0 to 1. It represents the proportion of scores in a distribution that a specific score is greater than. For example, a percent rank of 0.75 means that 75% of the data is below this point.