Percentage change from the previous salary
The task
The people team is reviewing pay changes since the start of 2024. For every salary that took effect from 2024-01-01 onward, compare it with the same employee's immediately previous salary.
The previous salary is the one with the latest earlier effective_on for that employee, even if it started before 2024. A salary with no earlier salary (the employee's first) is left out.
Return:
employee_ideffective_onprevious_salarysalary: the new salarychange_pct: the change from the previous salary as a percentage of the previous salary, rounded to 1 decimal place (a pay cut is negative)
Sort by employee_id, then effective_on.
Expected output
employee_ideffective_onprevious_salarysalarychange_pct- Sorted by 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.
| int | Unique id. | |
| text | Name. | |
| text | Main office city. |
employees120 rows in the sample
Everyone who has worked here, including people who left. Key: employee_id.
| int | Unique id. | |
| text | Name. | |
| int | Department. NULL for a few people between teams. | |
| int | Their manager (an employee_id). NULL for the CEO. | |
| text | Title. | |
| date | First day. | |
| date | Last 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.
| int | The employee. | |
| date | First day of this salary. | |
| numeric(10,2) | Yearly salary, USD. |
reviews301 rows in the sample
Year-end review ratings. Key: employee_id, review_year.
| int | The employee. | |
| int | Year reviewed. | |
| int | 1 (low) to 5 (high). |
Related questions
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL