新加一个辅助列flag,判断如果存在以当前编号为前缀的记录,flag置为N,如果不存在以当前编号为前缀的记录,flag置为Y,然后再过滤就可以了。
直接查询可以参照下面这个,效率不高
with temp as (
select '3' as col from dual
union
select '3.2' as col from dual
union
select '3.2.1' as col from dual
union
select '3.2.2' as col from dual
union
select '4' as col from dual
union
select '4.1' as col from dual
union
select '4.2' as col from dual
union
select '4.2.1' as col from dual
),
a as(
select t.col col1,t1.col col2,instr(t1.col,t.col,1,1) flag1,instr(t.col,t1.col,1,1) flag2
from temp t,temp t1
),
b as (
select * from a where flag1 <> 0 and flag2 <> 1
)
select distinct col2 from b where b.col2 not in (select col1 from b) order by col2