코딩테스트/MySQL
[프로그래머스 Level 3] 대장균들의 자식의 수 구하기 (MySQL)
최-코드
2024. 11. 20. 13:18
https://school.programmers.co.kr/learn/courses/30/lessons/299305
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
부모와 자식을 이어주기 위해 조인을 해줘야 한다. 이 때 자식이 없는 부모를 위해 left outer join을 해줘야 한다.
select f.id, count(s.parent_id) as child_count
from ecoli_data f left join ecoli_data s
on f.id = s.parent_id
group by f.id