Managers with a team of 20+: depts 13–22
Instructions
A manager's team is all subordinates at any level downward by manager_id (direct ones, the subordinates of direct ones, and so on), excluding the manager. There are no cycles in the hierarchy, and a chain of command is at most 5 levels long. For managers from departments with department_id from 13 to 22 inclusive, count team_size (the number of team members currently employed, with fired_at empty) and team_payroll (the sum of their salary). Subordinates may work in other departments; count them too. Output id, name, team_size, team_payroll only for managers with team_size of at least 20. Sort by team_size descending, then by id ascending.
Hints
Each next one is more detailed and costs more
Query
Result
Click Run to see the query result, or Check to submit your solution.
Dataset schema
Table relationships
- N:1Many-to-one
employees.→department_id departments.id - N:1Many-to-one
employees.→manager_id employees.id - N:1Many-to-one
departments.→parent_id departments.id - N:1Many-to-one
salary_history.→employee_id employees.id
Table data
Select a table in the diagram or list to view its rows.