People team
A 120-person company: departments, the reporting line, salary changes and yearly review ratings.
departments
One row per department. Key: department_id. 7 rows in the larger version, 4 in the smaller.
| department_id | int | Unique id. |
| department_name | text | Name. |
| office | text | Main office city. |
employees
Everyone who has worked here, including people who left. Key: employee_id. 120 rows in the larger version, 45 in the smaller.
| employee_id | int | Unique id. |
| full_name | text | Name. |
| department_id | int, nullable | Department. NULL for a few people between teams. |
| manager_id | int, nullable | Their manager (an employee_id). NULL for the CEO. |
| job_title | text | Title. |
| hire_date | date | First day. |
| termination_date | date, nullable | Last day. NULL while employed. |
| salary | numeric(10,2) | Current (or final) yearly salary, USD. |
salary_changes
Every salary someone has had, from the day it applied. Key: employee_id, effective_on. 367 rows in the larger version, 131 in the smaller.
| employee_id | int | The employee. |
| effective_on | date | First day of this salary. |
| salary | numeric(10,2) | Yearly salary, USD. |
reviews
Year-end review ratings. Key: employee_id, review_year. 301 rows in the larger version, 112 in the smaller.
| employee_id | int | The employee. |
| review_year | int | Year reviewed. |
| rating | int | 1 (low) to 5 (high). |
Questions on this database
- Headcount by department, empty and unassigned includedThe people team needs a headcount table that accounts for every department and every person. Count current employees only: those whose termination_date is NULL.
- Salary in effect at review time, by ratingThe people team asks whether higher ratings go with higher pay.
- Five longest-serving employees, keeping ties at the cut-offThe people team is planning a service-award event for the longest-serving current employees (termination_date is NULL). Rank them by hire_date, earliest first.
- Pay ladder with RANK and DENSE_RANK side by sideThe people team is drawing a pay ladder for every department and cannot decide how to number tied salaries, so they want both numberings next to each other.
- Top earner in each department, with a tie-breakerThe people team wants a one-line profile of the best paid current employee in every department.
- Employees in the top quarter of pay, by PERCENT_RANKCompensation wants to review the best paid people in each department. Use current employees only (termination_date is NULL) who belong to a department.
- Second highest salary in each departmentThe people team is checking pay bands and wants the second highest salary in every department, looking only at current employees (termination_date is...
- Percentage change from the previous salaryThe people team is reviewing pay changes since the start of 2024.
- Employees paid above their department averageThe people team is reviewing pay inside each department.
- Everyone who reports to a manager, at any depthWen Becker (employee_id 2) is leaving on sabbatical and the people team needs everyone in their organisation to hear about the cover plan.
- Reporting chain from an employee up to the CEOAn approval request from employee 33 needs to be routed up the reporting line.
- Headcount by level below the CEOThe people team wants to know how deep the reporting line goes. The CEO is the one employee with no manager_id.
- Colleagues hired in the same month and departmentThe people team wants to pair up colleagues who started together, for an onboarding buddy programme.
- Skip-level managers and how many people they coverThe people team plans skip-level one-on-ones. A skip-level manager is a person's manager's manager.
- Employees paid more than their managerThe people team is reviewing pay. Find employees who earn more than their manager. Consider only people still employed (termination_date is NULL).
- Raises of 9.5 percent or more over the previous salaryCompensation is auditing large raises. salary_changes has one row for each salary an employee has had, starting on effective_on.
- Salary in effect on a date for each employeeFinance is rebuilding the mid-year headcount cost report.
- Median salary by departmentThe people team reports pay with the median, because a few very high salaries pull the average up.
- A small data quality test suite as one queryThe data team runs these four checks on the HR tables every night.
- Salary validity ranges built with LEADThe HR warehouse needs a type 2 style table from the salary_changes log, so analysts can join pay to any date. Build it for employees of the Finance department.