[SQL] 570. There are at least 5 direct subordinate managers (build temporary table tmp)

insert image description here
insert image description here

Written one

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
    );

Writing method 2, build a temporary table 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;

Guess you like

Origin blog.csdn.net/xiaoyue_/article/details/129947593