LeetCode - 570. Managers with at Least 5 Direct Reports (MySQL)

조민수·2024년 6월 14일
0

LeetCode

목록 보기
36/64
post-custom-banner

Medium, SQL - Nested Query by own table

RunTime : 316 ms


문제

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.


풀이

  • managerId 필드에 5번 이상 등장하는 id값을 찾는 문제
  • 분명 풀어봤었는데 못 풀었다.
SELECT name FROM Employee
WHERE id IN (
    SELECT managerId
    FROM Employee
    GROUP BY 1
    HAVING COUNT(*) >= 5
)
profile
사람을 좋아하는 Front-End 개발자
post-custom-banner

0개의 댓글