表1 结构 a b c 均为主键 表2 结构 a b 均为主键
a b c a b d
1 2 3 1 2 5
1 2 4
1 2 6 以a,b为key 连接,像得到这样的结果,该如何做,请赐教:
a b c 5
1 2 3,4,6 6
select tt.a,tt.b,B.d,substr(max(sys_connect_by_path(tt.c, ', ')),2)
from (select A.a,A.b,A.c,1+row_number()over(partition by A,a,A.b order by A.a,A.b)seq1,
row_number()over(partition by A,a,A.b order by A.a,A.b) seq2 from A)tt,B
where tt.a=B.a
and tt.b=B.b
start with tt.seq2=1
connect by tt.seq2=prior tt.seq1
group by tt.a,tt.b,B.d 1。max(sys_connect_by_path(tt.c, ',')是什么意思?
2。但是现在如果表是这样的结构:表A
a b c
1 2 3
1 2 4
2 3 4
2 3 5
3 4 1
4 5 4
a,b,c均为主键,现在以a,b为KEY检索,结果为
a,b, c
1 2 3,4
2 3 4,5
3 4 1
4 5 4
用上述的方法就不可以,清高手指点!!!!
a b c a b d
1 2 3 1 2 5
1 2 4
1 2 6 以a,b为key 连接,像得到这样的结果,该如何做,请赐教:
a b c 5
1 2 3,4,6 6
select tt.a,tt.b,B.d,substr(max(sys_connect_by_path(tt.c, ', ')),2)
from (select A.a,A.b,A.c,1+row_number()over(partition by A,a,A.b order by A.a,A.b)seq1,
row_number()over(partition by A,a,A.b order by A.a,A.b) seq2 from A)tt,B
where tt.a=B.a
and tt.b=B.b
start with tt.seq2=1
connect by tt.seq2=prior tt.seq1
group by tt.a,tt.b,B.d 1。max(sys_connect_by_path(tt.c, ',')是什么意思?
2。但是现在如果表是这样的结构:表A
a b c
1 2 3
1 2 4
2 3 4
2 3 5
3 4 1
4 5 4
a,b,c均为主键,现在以a,b为KEY检索,结果为
a,b, c
1 2 3,4
2 3 4,5
3 4 1
4 5 4
用上述的方法就不可以,清高手指点!!!!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货