sql server的Case When Then关键字的使用


Case When Then

用法1:

 case [字段]
         when '字段等于相应的value' then 表达式
         when '字段等于相应的value' then 表达式
         else ''
      end 
   
eg:select sort,qty,
    case qty
      when 1 then '少'
      when 2 then '中'
      when 3 then '多'
      else '未知'
    end as [数量范围]
  from test

用法2:

case 
         when [条件] then 表达式
         when [条件] then 表达式
         else ''
      end 
select sort,qty,
    case 
      when qty=1 then '少'
      when qty=2 then '中'
      when qty=3 then '多'
      else '未知'
    end as [数量范围]
    from test 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM