1. 문제 출처

https://leetcode.com/problems/managers-with-at-least-5-direct-reports/description/?envType=study-plan-v2&envId=top-sql-50

2. 문제 의도

  • 계층형 데이터를 구하기 위한 self-join

3. 풀이

  • mangerid와 id를 키로 inner join 
  • groupy - having 조건을 이용하여 5개 이상의 부하직원이 있는 사람을 조회
select e2.name
from employee e1 inner join employee e2 on e1.managerid = e2.id
group by e1.managerid
having count(e1.id) >=5
order by e1.id asc

+ Recent posts