三个不同id的结果表合并到一张表里,每个表的结果是单独一个列:
1.首先,创建三张表
create table t1(t_id varchar2(20),t_name varchar(20));
insert into t1(t_id,t_name) values(1,'对');
insert into t1(t_id,t_name) values(2,'对');
insert into t1(t_id,t_name) values(3,'对');
create table t3(t_id varchar2(20),t_name varchar(20));
insert into t3(t_id,t_name) values(2,'错');
insert into t3(t_id,t_name) values(3,'错');
insert into t3(t_id,t_name) values(4,'错');
create table t3(t_id varchar2(20),t_name varchar(20));
insert into t3(t_id,t_name) values(3,'好');
insert into t3(t_id,t_name) values(4,'好');
insert into t3(t_id,t_name) values(5,'好');
2.然后,使用full join,先把两张表合并到一起
select nvl(t1.t_id,t2.t_id) t_id,nvl(t1.t_name,null) t_name1,nvl(t2.t_name,null) t_name2
from t1 full join t2 on t1.t_id = t2.t_id
3.最后,把这两张表的合并后的结果和第三张结果表合并
select nvl(t4.t_id,t3.t_id) id,nvl(t4.t_name1,null) value1,nvl(t4.t_name2,null) value2,nvl(t3.t_name,null) value3 from
(select nvl(t1.t_id,t2.t_id) t_id,nvl(t1.t_name,null) t_name1,nvl(t2.t_name,null) t_name2
from t1 full join t2 on t1.t_id = t2.t_id ) t4 full join t3 on t4.t_id = t3.t_id
order by id;