case a<=b then a when a>b and b>0 then a-b when b<0 then 0 end

解决方案 »

  1.   

    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)
      

  2.   

    case when a<=b then a when a>b and b>0 then a-b when b<0 then 0 end
      

  3.   

    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
      

  4.   

    最后的 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)
      

  5.   


    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)
      

  6.   

    谢谢各位啊。我结帖了。呵呵~~~
    TO nforcedzh(翔天)谢谢你的提醒啊。其实我有个条件没有说啊。就是A一定是正数啊。呵呵~~~谢谢你的提醒。