ALTER TABLE 表 ADD c as (case when a<=b then a when a>b and b>0 then a-b when b<0 then 0 end)
case when a<=b then a when a>b and b>0 then a-b when b<0 then 0 end
insert into table1 (field1) select case when a<=b then a when a>b and b>0 then a-b when b<0 then 0 end
最后的 b<0产生了二义性(有可能a<b或a>b),从你程序的if语句的含义,应改成 a>b and b<0 ALTER TABLE 表 ADD c as (case when a<=b then a when a>b and b>0 then a-b when a>b and b<0 then 0 end)
c=(case when a<=b then a when a<=b and a>b and b>0 then a-b when a<=b and b<0 then 0 end)
谢谢各位啊。我结帖了。呵呵~~~ TO nforcedzh(翔天)谢谢你的提醒啊。其实我有个条件没有说啊。就是A一定是正数啊。呵呵~~~谢谢你的提醒。
select case when a<=b then a when a>b and b>0 then a-b when b<0 then 0 end
ALTER TABLE 表 ADD c as (case when a<=b then a when a>b and b>0 then a-b when a>b and b<0 then 0 end)
c=(case
when a<=b then a
when a<=b and a>b and b>0 then a-b
when a<=b and b<0 then 0
end)
TO nforcedzh(翔天)谢谢你的提醒啊。其实我有个条件没有说啊。就是A一定是正数啊。呵呵~~~谢谢你的提醒。