力扣数据库热题70--No.570题解

官方难度中等,体感稍简单,有两种比较简单的做法。

第一种是子查询,需要找到该经理id的名称。

select name
from Employee
where id in 
    (select managerId
    from Employee
    group by managerId
    having count(*) >= 5)

第二种是联表,原表没有列出对应的经理名称。

with tmp as
(select e1.id,e1.name,e1.department,e1.managerId,e2.name as managerName
from Employee e1 join Employee e2
on e1.managerId = e2.id)

select managerName as name
from tmp
group by managerId
having count(*) >= 5
posted @ 2026-08-30 02:46  找回那所有、  阅读(10)  评论(0)    收藏  举报
这里到底了哦~(●'◡'●)