森林渔业
create table tt(ch varchar(20))
insert tt select '1001001'
union all select '1001'
union all select '2001001'
union all select '2001'
union all select '300120013001'
union all select '4001'
--求森林的根
select *
from tt as t1
where not exists
(select 1
from tt as t2
where t1.ch like t2.ch+'%'
and t1.ch!=t2.ch)
--求森林的叶
select *
from tt as t1
where not exists
(select 1
from tt as t2
where t2.ch like t1.ch+'%'
and t1.ch!=t2.ch)