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:
![](https://img-blog.csdnimg.cn/img_convert/2982f448504941c18f6e0486fd8fb8a7.png)
table sample
employees table:
![](https://img-blog.csdnimg.cn/img_convert/3522c93f1bb744fbb6f683aeafa77218.png)
Sample output:
![](https://img-blog.csdnimg.cn/img_convert/6737689483da49eabe8e3caae7baded1.png)
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
![](https://img-blog.csdnimg.cn/img_convert/a933dc6f26bd4a6687e9a4f073eded40.png)