← CTE

Salary growth of 12%+: departments 14–20, Jan 2023–Dec 2024

Level: Middle100 XP

Instructions

Consider the salary_history records with changed_at on or after January 1, 2023 and strictly before January 1, 2025. 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 14 to 20 inclusive whose last_salary grew relative to first_salary by at least 12% (last_salary >= first_salary * 1.12). 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