首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

SQL

2012-05-23 
SQL求助有如下两张表A TABLEIDID_VERSION100011000210003B TABLEIDID_NUM1000310004求结果表如下RESULTIDI

SQL求助
有如下两张表
A TABLE
IDID_VERSION
10001
10002
10003

B TABLE
IDID_NUM
10003
10004

求结果表如下
RESULT
IDID_VERSIONID_NUM
10001
10002
100033
10004

各位大虾,如何写相应的SQL文呢?

[解决办法]

SQL code
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_numorder by a.id,a.id_version       id   ID_VERSION id_num -----------------------------------------1    1000    1    2    1000    2    3    1000    3    34    1000    4    45    1000    5    6    2000    5    57    2000        4 

热点排行
Bad Request.