想象一下下表
DEPARTURE_ID ARRIVE_ID ORDER
------------- --------- -----
1 3 1
2 3 2
3 (null) 3
10 12 1
11 13 2
12 15 3
13 15 4
14 15 5
15 (null) 6
25 27 1
26 27 2
27 (null) 3
我想保留以前的arrival_id
连接的departure_id在oracle11g中,我这样做
样本表
create table dep_arrives ( departureid, arrriveid, ord) as
select '1', '3', 1 from dual union all
select '2', '3', 2 from dual union all
select '3', null, 3 from dual union all
select '10', '12', 1 from dual union all
select '11', '13', 2 from dual union all
select '12', '15', 3 from dual union all
select '13', '15', 4 from dual union all
select '14', '15', 5 from dual union all
select '15', null, 6 from dual union all
select '25', '27', 1 from dual union all
select '26', '27', 2 from dual union all
select '27', null, 3 from dual
;
选择陈述
select departureid
from dep_arrives
start with ord = 1
connect by departureid = prior arrriveid
结果
DEPARTURE_ID
1
3
10
12
15
25
27
我知道在netezza中没有连接的开始,所以我正在寻找netezza sql的解决方法。
提前致谢。