直接入正题
现假设条件为common的在A表中的某个字段为a,同样的条件common在B表中的某个字段为b
a,b类型均为NUMBER
需要将a,b按照不同情况的组合合并为另两个字段,先定为c,和d好了(表达能力不太好,望见谅)
现在有四种情况
1、若a>=0,b>=0,则c=a+b,d=0;
2、若a>=0,b<0, 则c=a,d=b;
3,若a<0,b>=0,则c=b,d=a;
4,若a<0,b<0,则c=0,d=a+b;
最终select出来的结果为   common,c,d不知道如何下手,望各位大大们给点思路
在线等
感谢各位啦

解决方案 »

  1.   

    先case试试啊~ 应该没问题吧
      

  2.   


    --参考:
    select a.common,
          case 
              when a.a>=0 and b.b>=0 then a.a+b.b
              when a.a>=0 and b.b<0 then a.a
              when a.a<0 and b.b>=0 then b.b
              else 0
          end c,
          case
              when a.a>=0 and b.b>=0 then 0
              when a.a>=0 and b.b<0 then b.b
              when a.a<0 and b.b>=0 then a.a
              else a.a+b.b
          end d
    from a,b
    where --a表,b表的连接条件