select case opt_type when 0 then (case buybill when null then 1 else 0 end) else 2 end billtype from 表A

解决方案 »

  1.   

    select billtype =
    case
    when buybill is not null and opt_type='0' then '0'
    when buybill is null and opt_type='0' then '1'
    when opt_type='1' then '2'
    end 
    from 表
      

  2.   

    select billtype = case
           when buybill  is not null and opt_type='0'  then '0'
           when buybill  is  null and opt_type='0'  then '1'
           whenopt_type='1'  then '2'
          end
    from 表A
      

  3.   

    case  when  buybill is not null and  opt_type='0' then billtype='0'
    else when buybill is null and opt_type='0'  then billtype='1'
    else billtype='2' end