首页 > 数据库技术 > 详细

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

时间:2019-09-19 11:17:31      阅读:99      评论:0      收藏:0      [点我收藏+]

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 

 

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

原文:https://www.cnblogs.com/echola/p/11547759.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!