日期:2014-05-17 浏览次数:20762 次
with table1 as( select 'a1' A,'b1' B, 'c1' C from dual union all select 'a1' A,'b2' B, 'c2' C from dual union all select 'a1' A,'b3' B, 'c3' C from dual union all select 'a2' A,'b2' B, 'c1' C from dual union all select 'a2' A,'b4' B, 'c4' C from dual), table2 as( select 'a1' A, 'd1' D from dual union all select 'a1' A, 'd2' D from dual union all select 'a2' A, 'd3' D from dual) SELECT t1.A, t1.B, t1.C, t2.D FROM (SELECT t.*, row_number() over(PARTITION BY A ORDER BY A, B, C) rn FROM table1 t) t1, (SELECT t.*, row_number() over(PARTITION BY A ORDER BY A, D) rn FROM table2 t) t2 WHERE t1.A = t2.A(+) AND t1.rn = t2.rn(+) ORDER BY t1.A, t1.B, t1.C;