SELECT a.id,ifnull(child_count,0) CHILD_COUNT
from ecoli_data a
left join (select parent_id,count(*) child_count
from ecoli_data
where parent_id is not null
group by parent_id) b
on a.id = b.parent_id
order by 1 asc
select a.id,count(b.parent_id) CHILD_COUNT
from ecoli_data a
left join ecoli_data b
on a.id = b.parent_id
group by 1
order by 1 asc
굳이 join에 서브쿼리 쓸 필요가 없었다.