select * from a,b where a.b(+)=b.b
解决方案 »
- oracle 11.2.0 监听器状态代码,各项信息是否有误
- ORA中如何锁定行数据
- group by 的问题
- 关于dbms_output.put_line输出问题.
- sql:select 0.15||'aaa' from dual;得到.15aaa而不是0.15aaa
- 哪种情况下用触发器的before,什么时候用after比较合适?
- 增加主键和外键的问题
- 怎样用Erwin导出Oracle的表结构以及索引等建表脚本而不导出数据,明天我要交货啊!!
- 在ORACLE中,一数据文件大于2G,我删掉了部分数据,可是查看文件大小仍没变
- 谁知道哪里有oracle 内部函数一览(包含帮助)下载?
- 怎样让表里的内容按顺序存储??
- 急救!!!!!!!!!!!!!
try:
select nvl(a.a,b.a),nvl(a.b,b.b),nvl(a.c,b.c),a.d,b.d from a full outer join b on (a.a=b.a and a.b=b.b and a.c=b.c);
从你的描述,我理解A,B表在前三个字段上是不完全相同又存在交集,所以就存在三类数据
对于前三个字段的值:
1)A、B表均有的;
2)A表有,B表无;
3)A表无,B表有。select A.a,A.b,A.c,A.d,B.d from A,B where A.a = B.a and A.a = B.a and A.b = B.b and A.c = B.c ---第一种情况
union
select A.a,A.b,A.c,A.d,0 from A,B where not exists( select * from B where A.a = B.a and A.a = B.a and A.b = B.b and A.c = B.c) ---第二种情况
union
select B.a,B.b,B.c,0,B.d from A,B where not exists( select * from A where A.a = B.a and A.a = B.a and A.b = B.b and A.c = B.c); ---第三种情况
现在改用mysql了所以无法测试写的对不对,试试看吧,可能还是考虑的不周密
敲abcd敲的好枯燥啊~~~~
(select a,b,c,d,1 e from A
union all
select a,b,c,d,-1 e
from B)
group by a,b,cA B C SUM(DECODE(E,1,D,0)) SUM(DECODE(E,-1,D,0))
----- ----- ----- -------------------- ---------------------
2005 u1 001 100 600
2005 u1 002 200 500
2005 u1 003 300 0
2005 u1 004 0 400
2005 u1 005 0 300
2005 u2 001 400 200
2005 u2 002 0 100