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.
"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
level, headcount, avg_salary (rounded to a whole number); sorted by levelExample of the shape (made-up values):
| level | headcount | avg_salary |
|---|---|---|
| 1 | 1 | 350000 |
| 2 | 4 | 230000 |
Hints, the later steps and the answer come with Pro.
Step 1 of 4
Write your query here. Ctrl + Enter submits.