머리가 굳은 것 같다. 그림을 그려서 생각을 먼저 하고 코드를 짜야 수월하다. 많이 풀어보고 내것으로 만들어야겠다. 이 방법뿐…

Image Alt photo_exhibition

Write a solution to find managers with at least five direct reports.

Return the result table in any order.

The result format is in the following example.

Image Alt photo_exhibition

셀프조인을 하면 아래와 같이 테이블이 된다. (머릿속에 계속 연상해보기)

id name department managerId id name
101 John A null null null
102 Dan A 101 101 John
103 James A 101 101 John
104 Amy A 101 101 John
105 Anne A 101 101 John
SELECT e2.name
FROM Employee e1
INNER JOIN Employee e2
ON e1.managerId = e2.id -- 셀프조인
GROUP BY e1.managerId
HAVING COUNT(e1.managerId) >= 5