← CTE

Salary growth of 5%+: departments 4–11, Jul 2022–Jun 2024

Level: Middle100 XP

Instructions

Consider the salary_history records with changed_at on or after July 1, 2022 and strictly before July 1, 2024. For each employee who has such records, take the earliest salary by date (first_salary) and the latest by date (last_salary) among them. Find employees of the departments with department_id from 4 to 11 inclusive whose last_salary grew relative to first_salary by at least 5% (last_salary >= first_salary * 1.05). Output id, name, first_salary, last_salary and growth_pct, the growth as a percentage of first_salary, rounded to 1 decimal place. Row order does not matter.

Hints

Each next one is more detailed and costs more

Log in to open hints

Query

Result

Click Run to see the query result, or Check to submit your solution.

Dataset schema

employees.department_id (0…N) ↔ departments.id (1…1)employees.manager_id (0…N) ↔ employees.id (0…1)departments.parent_id (0…N) ↔ departments.id (0…1)salary_history.employee_id (0…N) ↔ employees.id (1…1)departmentsPKidintegerFKparent_idintegeremployeesPKidintegerFKdepartment_idintegerFKmanager_idintegersalary_historyPKFKemployee_idintegerPKchanged_atdate
Exactly oneZero or oneZero or more
Table relationships
  • N:1Many-to-oneemployees.department_id → departments.id
  • N:1Many-to-oneemployees.manager_id → employees.id
  • N:1Many-to-onedepartments.parent_id → departments.id
  • N:1Many-to-onesalary_history.employee_id → employees.id

Table data

PostgreSQL

Select a table in the diagram or list to view its rows.

Dataset schema