日期:2014-05-16 浏览次数:20944 次
with t as (
select '1' id,'0' pid from dual
union all
select '2' id,'1' pid from dual
union all
select '3' id,'1' pid from dual
union all
select '4' id,'3' pid from dual
union all
select '5' id,'1' pid from dual
union all
select '6' id,'2' pid from dual
)
select t.id,
(select count(1)
from t tt
start with tt.pid = t.id
connect by prior tt.id = tt.pid)
from t