请教大家,取这个树的最顶级节点,该怎么写!
建表和填充记录,
create table test(superid varchar2(20),id varchar2(20));
insert into test values('1','11');
insert into test values('1','12');
insert into test values('2','21');
insert into test values('2','22');
insert into test values('11','111');
insert into test values('11','112');
insert into test values('12','121');
insert into test values('12','122');
insert into test values('21','211');
insert into test values('21','212');
insert into test values('22','221');
insert into test values('22','222');
commit;
想通过一个sql语句查询重如下结果:
ID superid topSuperid(最顶层ID)
1 0 0
111 11 1
211 21 2
请问大家有方法么?