【SQL】570. 至少有5名直接下属的经理 (构建临时表tmp)

在这里插入图片描述
在这里插入图片描述

写法一

select a.name
from Employee a
where a.id = (
    select b.managerId
    from Employee b
    where a.id = b.managerId
    group by b.managerId
    having COUNT(*) >= 5
    );

写法二,构建临时表tmp

select a.name
from Employee as a
join (
    select managerId
    from Employee
    group by managerId
    having COUNT(*) >= 5
) as tmp
on a.id = tmp.managerId;

猜你喜欢

转载自blog.csdn.net/xiaoyue_/article/details/129947593