Query the number of direct subordinates of each leader, display: the leader's employee number (EmployeeID), the number of subordinates (renamed to (countSub))
Tip: Please use the SELECT statement to answer.
Table Structure:
table sample
employees table:
Sample output:
Code length limit 16 KB
Time limit 400 ms
DatabaseMySQL
The result output requires a strict comparison of the order and data
select b.EmployeeID, count(*) countSub
from employees a, employees b
where a.ReportsTo = b.EmployeeID
group by b.EmployeeID