[LeetCode/SQL] 570. Managers with at Least 5 Direct Reports

Sooyeon·2024년 1월 11일
0

문제풀이 

목록 보기
75/95
post-thumbnail

[LeetCode/SQL]


📌 570. Managers with at Least 5 Direct Reports

문제

풀이

5명 이상의 직속 부하 직원이 있는 관리자를 찾아라

방법 I

SELECT name 
FROM Employee 
WHERE id IN (
    SELECT managerId 
    FROM Employee 
    GROUP BY managerId 
    HAVING COUNT(*) >= 5)

방법 II

SELECT m.name
FROM employee as e
INNER JOIN employee as m
ON e.managerId=m.id
GROUP BY e.managerId 
HAVING COUNT(m.id)>=5

0개의 댓글