本帖最后由 zxffling 于 2011-09-26 22:12:27 编辑

解决方案 »

  1.   

    楼主是这个意思?
    select 字段1,字段2,字段3
        ,case when 字段2-字段3 > 0 then 字段2-字段3 else null end 新增数
        ,case when 字段2-字段3 < 0 then 字段2-字段3 else null end 净减数
      from table1
      where ...
      

  2.   

    如果楼主要把值存入表中,就要用UPDATE 进行更新数据, 可以这样update table1 set 新增数=字段2-字段3 where 新增数=0 or 新增数 is null;
    update table1 set 净减数=字段2-字段3 where 新增数=0 or 新增数 is null;
    条件自己确定,
    再用: update table1 set 新增数=0 where 新增数<0;
          update table1 set 净减数=0 where 净减数>0; 
      

  3.   

    按照条件,执行UPDATE,分别执行2个,字段2-字段3 比较
      

  4.   

    update table1 set 新增数=字段2-字段3,净减数=null;
    update table1 set 净减数=新增数 where 新增数<0;
    update table1 set 新增数=null where 新增数<0;
      

  5.   

    用decode(sign(a-b),1,参数)的函数搞定了,谢谢给我 结贴了