Skip to content

PERCENT

SELECT EMPLOYEE_ID, LAST_NAME, SALARY,
PERCENT_RANK () OVER (ORDER BY SALARY DESC) "Percent Rank"
FROM EMPLOYEES
ORDER BY SALARY DESC;
EMPLOYEE_ID | LAST_NAME | SALARY | Percent Rank
-------------|-----------|----------|-----------------
100 | King | 24000 | 0
101 | Kochhar | 17000 | 0.0222222222222222
102 | De Haan | 17000 | 0.0222222222222222
103 | Hunold | 9000 | 0.0666666666666667

The example uses the PERCENT_RANK() function in Oracle SQL to calculate the percentile rank of each employee’s salary compared to all other salaries in the ‘EMPLOYEES’ table. The PERCENT_RANK() function computes the relative rank of a row returned by a query in the form of a percentage between 0 and 1. The highest salary has a percent rank of 0, and all other salaries are ranked accordingly.