select * from a,b where a.b(+)=b.b

解决方案 »

  1.   

    9i?
    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);
      

  2.   

    笨办法,用union
       从你的描述,我理解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敲的好枯燥啊~~~~
      

  3.   

    帖子发出去,发现别人用nvl函数,真惭愧,笨死了
      

  4.   

    bzszp(SongZip) 的逻辑是对的
      

  5.   

    select a,b,c,sum(decode(e,1,d,0)),sum(decode(e,-1,d,0)) from 
    (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