用 CASE.....WHEN 结构实现

解决方案 »

  1.   

    用 CASE.....WHEN 结构
    case when 1=1 then 2 else 3 end
      

  2.   

    case when 更强大--超过两项
    select
    case x when
       'A' then 1
       'B' then 2
       'C' then 3
       'D' then 4
       'E' then 5
       else 6
     end as x
    from tablename--可以嵌套
    select
    case x when
       'A' then case when y<0 then 0
                when y>=0 and y<=10 then y
                else 10
                end
       else case when y<0 then -1
                when y>=0 and y<=10 then 0
                else 1
                end
     end as xy
    from tablename等等