至少有5名直接下属的经理
题目分析:表中给了职员以及职员的经理是谁,要找出至少有5名下属的经理。
首先可以找出至少有5名下属的经理的ManagerId。
select ManagerId from Employee where ManagerId is not null group by ManagerId having count(*) >=5
接着通过查找出的ManagerId进行筛选就可以了
select name from Employee where Id in (
select ManagerId from Employee where ManagerId is not null group by ManagerId having count(*) >=5)
提交结果如下