Skip to content

Employees in the top quarter of pay, by PERCENT_RANK

MediumFull bankRanking and top N14 min2 hidden datasets

The task

Compensation wants to review the best paid people in each department. Use current employees only (termination_date is NULL) who belong to a department. Within each department, compute each person's pay percentile with PERCENT_RANK: order by salary from lowest to highest, so the lowest salary is 0 and the highest is 1.

Return the people whose percentile is at least 0.75, comparing the exact value, not a rounded one. People on the same salary get the same percentile.

Return department_name, full_name, salary and pay_percentile (the exact percentile rounded to 2 decimal places). Sort by department_name ascending, then pay_percentile descending, then full_name ascending.

Expected output

department_namefull_namesalarypay_percentile
  • Sorted by department_name ascending, then pay_percentile descending, then full_name ascending.
  • Numbers rounded to 2 decimal places.
  • Checked on the sample and on 2 hidden datasets. How grading works

Tables People team · click a name to insert it

departments7 rows in the sample

One row per department. Key: department_id.

intUnique id.
textName.
textMain office city.
employees120 rows in the sample

Everyone who has worked here, including people who left. Key: employee_id.

intUnique id.
textName.
intDepartment. NULL for a few people between teams.
intTheir manager (an employee_id). NULL for the CEO.
textTitle.
dateFirst day.
dateLast day. NULL while employed.
numeric(10,2)Current (or final) yearly salary, USD.
salary_changes367 rows in the sample

Every salary someone has had, from the day it applied. Key: employee_id, effective_on.

intThe employee.
dateFirst day of this salary.
numeric(10,2)Yearly salary, USD.
reviews301 rows in the sample

Year-end review ratings. Key: employee_id, review_year.

intThe employee.
intYear reviewed.
int1 (low) to 5 (high).

Related questions

Loading the editor and PostgreSQL