🍋 ⚾️ 💻 🎬 🎮

coding_test/SQL 문제

[LeetCode] 570. Managers with at Least 5 Direct Reports (JOIN)

aeightchill 2025. 2. 8. 15:10
728x90

< 문제 >

[SQL50] 570. Managers with at Least 5 Direct Reports (JOIN)



< 풀이 >

WITH direct AS(
    SELECT managerId, SUM(1) AS manage_cnt
    FROM Employee
    WHERE managerId IS NOT NULL
    GROUP BY managerId)

SELECT A.name
FROM Employee A LEFT JOIN direct B ON A.id = B.managerID
WHERE B.manage_cnt >= 5;
728x90