Skip to content

Raises of 9.5 percent or more over the previous salary

The task

Compensation is auditing large raises. salary_changes has one row for each salary an employee has had, starting on effective_on.

For every salary row that has an earlier row for the same employee, compare it with the salary row immediately before it: the one with the latest effective_on that is still earlier. This is the previous salary, whether it was higher or lower than the ones before it.

Keep the rows where the new salary is at least 9.5 percent above the previous salary. The test uses the exact percentage, not the rounded one. The employee's first salary row has nothing to compare with and is never returned.

Return employee_id, effective_on, previous_salary, new_salary and raise_pct (the raise as a percentage of the previous salary, rounded to 1 decimal place). Sort by raise_pct descending, then employee_id, then effective_on.

Expected output

employee_ideffective_onprevious_salarynew_salaryraise_pct
  • Sorted by raise_pct descending, then employee_id ascending, then effective_on ascending.
  • Numbers rounded to 1 decimal place.
  • 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