Simplify nested case when statement

前端 未结 3 880
你的背包
你的背包 2021-01-06 04:25

Below is my current SELECT CASE statement:

SELECT CASE 
WHEN edition = \'STAN\' AND has9 = 1 THEN \'9\'
WHEN edition = \'STAN\' AND has8 = 1 THEN \'8\'
WHEN          


        
3条回答
  •  灰色年华
    2021-01-06 05:06

    You can nest your case when.

    By the way, when you make a case on a single field, you can do

    case  when 
                 when 
    

    rather then

     case when  = 
          when  = 
    

    So

    case edition
          when 'STAN'
             case when has9 = 1 then '9'
                  when has8 = 1 then '8'
                  when has7 = 1 then '7'
                  when hasOLD = 1 then 'OLD'
             end
         when 'SUI'
             case when has_s9 = 1 then 'S9'
                  when has_s8 = 1 then 'S8'
             end
         else 'S7'
    end as version
    

提交回复
热议问题