当前位置: 代码迷 >> Sql Server >> 这样的分类语句能简化吗解决思路
  详细解决方案

这样的分类语句能简化吗解决思路

热度:77   发布时间:2016-04-27 16:32:07.0
这样的分类语句能简化吗
如题
select   case   月度  
when   1   then   '第一季度 '  
when   2   then   '第一季度 '
when   3   then   '第一季度 '
when   4   then   '第二季度 '
...
when   12   then   '第四季度 '

end
as   季度
    from   Table  

我想简化成类似:

select   case   月度  
when   1,2,3   then   '第一季度 '  
when   4,5,6   then   '第2季度 '
when   7,8,9   then   '第3季度 '
when   10,11,12,13   then   '第4季度 '

end
as   季度
    from   Table

------解决方案--------------------
select case
when 月度 in(1,2,3) then '第一季度 '
when 月度 in(4,5,6) then '第2季度 '
when 月度 in(7,8,9) then '第3季度 '
else '第4季度 '
end
as 季度
from Table1
  相关解决方案