表记录:
1002
100201
1002018523532
100201435X46413
100202
1002026335332
2001
200101
200102
我现在需要得到哪些节点是分支节点,哪些是叶子节点。实际上:1002,100201,100202,2001是分支节点,其他都是叶子节点。可以肯定的是,同个父节点下的分支节点(非叶子节点)的长度是一样的。
------解决方案--------------------
1--非叶子
0-叶子节点
lvl为层次:
with t as
(select '1002' c1
from dual
union all
select '100201' c1
from dual
union all
select '1002018523532' c1
from dual
union all
select '100201435X46413' c1
from dual
union all
select '100202' c1
from dual
union all
select '1002026335332' c1
from dual
union all
select '2001' c1
from dual
union all
select '200101' c1
from dual
union all
select '200102' c1
from dual)
select t3.c1, t3.lvl, t4.is_leaf
from (select t2.c1, count(1) lvl
from t t1, t t2
where t2.c1 like t1.c1
------解决方案--------------------
'%'
group by t2.c1
order by t2.c1) t3,
(select c1,
decode((select count(*)
from t t2
where t2.c1 like t1.c1
------解决方案--------------------
'%'
and t2.c1 <> t1.c1),
0,
0,
1) is_leaf
from t t1) t4
where t3.c1 = t4.c1;
------解决方案--------------------