日期:2014-05-17 浏览次数:20834 次
create table test1(id number(5),ID_VERSION number(2)); insert into test1 values(1000,1); insert into test1 values(1000,2); insert into test1 values(1000,3); insert into test1 values(1000,4); insert into test1 values(1000,5); insert into test1 values(2000,5); create table test2(id number(5),ID_NUM number(2)); insert into test2 values(1000,3); insert into test2 values(1000,4); insert into test2 values(2000,4); insert into test2 values(2000,5); select case when a.id is null then b.id else a.id end id, a.id_version,b.id_num from test1 a full join test2 b on a.id=b.id and a.id_version=b.id_num order by a.id,a.id_version id ID_VERSION id_num ----------------------------------------- 1 1000 1 2 1000 2 3 1000 3 3 4 1000 4 4 5 1000 5 6 2000 5 5 7 2000 4