Pay at each level of the org chart

HardMicrosoftrecursive ctejoinsaggregation· 40 XP

Microsoft's HR team wants to see how headcount and pay change as you go down the org chart: CEO at level 1, the people reporting to the CEO at level 2, and so on.

Work out every employee's level (the CEO, who has no manager, is level 1). Then show, per level, the number of people and their average salary.

Expected output

  • avg_salary rounded to a whole number; sorted by level

Example of the shape (made-up values):

level people avg_salary
1 1 400000
2 5 251000

Hints, the later steps and the answer come with Pro.

Write your query here. Ctrl + Enter submits.