Reporting chain from an employee up to the CEO
The task
An approval request from employee 33 needs to be routed up the reporting line. List the full chain: employee 33 first, then their manager, then that manager's manager, and so on up to the CEO (the employee with no manager_id).
Include everyone on the chain, including people who have left. Return step, employee_id, full_name and job_title, where step is 0 for employee 33, 1 for their manager, and goes up by one for each level. Sort by step.
Expected output
stepemployee_idfull_namejob_title- Sorted by step ascending.
- 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