sql语句中,我怎么计算一个月份是第几个季度的?例:7月份,用一个算法,直接知道他是属于第三季度?

如题所述

select case
when month between 1 and 3 then '一季度'
when month between 4 and 6 then '二季度'
when month between 7 and 9 then '三季度'
when month between 10 and 12 then '四季度'
end as 季度
from table

这样就可以了
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-12-20
select CEILING(convert(real,7)/3)

=======================
把7换成你要算的月份就可以了本回答被提问者采纳
第2个回答  2011-12-20
DateName (interval,date) 返回日期date中,interval指定部分所对应的字符串名称
参数 interval的设定值如下:
Quarter Qq q 季 1 ~ 4