id name parent-id 1 x 0 2 y 0 3 z 0 4 a 1 5 b 2 6 c 1 7 d 4 8 e 4
id name parent-id total-child 1 x 0 2 2 y 0 1 3 z 0 0 4 a 1 2 5 b 2 0 6 c 1 0 7 d 4 0 8 e 4 0
答案 0 :(得分:1)
select id,
name,
(select count(*) from table t2 where t2.parent-id=t1.id) as child-count
from table t1