Org chart and project costs
HardMicrosoftrecursive ctesorg levelsself joinscost allocation· 160 XP (40 per question)
Mock interview. You're interviewing for a senior people analytics job. The interviewer says: "We're planning next year's budget. I'd like a clear picture of the org structure, a pay sanity check, and what our projects really cost in salaries."
employees.manager_id points to each person's manager. The top boss has an empty manager_id.
Question 1: Levels in the org
"Using a recursive query, work out each person's level (the top boss is level 1, their reports are level 2, and so on). Show headcount and average salary per level."
Expected output
- Columns
level,headcount,avg_salary(rounded to a whole number); sorted bylevel
Example of the shape (made-up values):
| level | headcount | avg_salary |
|---|---|---|
| 1 | 1 | 350000 |
| 2 | 4 | 230000 |
Hints, the later questions and the answer come with Pro.
Question 1 of 4
Write your query here. Ctrl + Enter submits.