楼主是这个意思? 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 ...
如果楼主要把值存入表中,就要用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;
按照条件,执行UPDATE,分别执行2个,字段2-字段3 比较
update table1 set 新增数=字段2-字段3,净减数=null; update table1 set 净减数=新增数 where 新增数<0; update table1 set 新增数=null where 新增数<0;
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 ...
update table1 set 净减数=字段2-字段3 where 新增数=0 or 新增数 is null;
条件自己确定,
再用: update table1 set 新增数=0 where 新增数<0;
update table1 set 净减数=0 where 净减数>0;
update table1 set 净减数=新增数 where 新增数<0;
update table1 set 新增数=null where 新增数<0;