oracle 外连接

//oracle 外连接 //from table_name1 {left | right | full} outer join table_name2 //using (common_column) //table_name1,table_name2是两个连接的表 //left:左外连接 //right:右外连接 //full:全连接,左外连接和右外连接的并集 //下面是一个实例: with ta as( select 101 wlbh,4 cssl from dual union all select 301,5 from dual union all select 501,6 from dual union all select 102,0 from dual union all select 201,0 from dual) ,tb as( select 101 wlbh,2 rksl from dual union all select 102,4 from dual union all select 301,5 from dual union all select 101,1 from dual) ,tc as( select 101 wlbh,3 cksl from dual union all select 102,1 from dual union all select 201,5 from dual union all select 101,2 from dual) select * from (select wlbh,nvl(cssl,0) cssl,nvl(rksl,0) rksl,nvl(cksl,0) cksl from (select wlbh,sum(cssl) cssl from ta group by wlbh) full outer join (select wlbh,sum(rksl) rksl from tb group by wlbh) using (wlbh) full outer join (select wlbh,sum(cksl) cksl from tc group by wlbh) using (wlbh)) order by wlbh / WLBH CSSL RKSL CKSL ---------- ---------- ---------- ---------- 101 4 3 5 102 0 4 1 201 0 0 5 301 5 5 0 501 6 0 0 

原帖:

http://topic.csdn.net/u/20110522/13/5f9ab43e-8e2c-4972-bc82-a6d28f2c5689.html?48408

你可能感兴趣的:(oracle 外连接)