Simplify nested case when statement

前端 未结 3 854
你的背包
你的背包 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:12

    Try this

    SELECT CASE 
    WHEN edition = 'STAN' THEN 
         CASE 
              WHEN has9 = 1 THEN '9'
              WHEN has8 = 1 THEN '8'
              WHEN has7 = 1 THEN '7'
              WHEN hasOLD = 1 THEN 'OLD'
         END
    WHEN edition = 'SUI' THEN
         CASE 
              WHEN has9 = 1 THEN 'S9'
              WHEN has8 = 1 THEN 'S8'
         END
    ELSE 'S7' END AS version
    

提交回复
热议问题