如何使用 connect by 获取层次结构的顶部和底部,我有一个存储 id 之间转换的表(ID-> REPLACE_ID),我有兴趣从任何 id 开始获取最新的 id。
--drop table test_connect_by;
create table test_connect_by(ID number, REPLACE_ID NUMBER);
insert into test_connect_by values(1,2);
insert into test_connect_by values(2,3);
insert into test_connect_by values(3,4);
insert into test_connect_by values(51,52);
insert into test_connect_by values(52,53);
insert into test_connect_by values(53,54);
insert into test_connect_by values(55,55);
SELECT id,replace_id, level
FROM test_connect_by
START WITH ID in (1,51)
CONNECT BY PRIOR replace_id = id;
我有兴趣从 1-4 和 51-54 转换,或者我可以从 2 开始并获得 2-4。有什么我可以分组来识别以 1 开头的组和以 51 开头的组吗?