SqlServer一季度查询

删库到跑路 2019-12-09 04:44:35
每年的12月26号为开始时间,
12月26号到3月26号为一季度
3月26号到6月26号为2季度
6月26号到9月26号为三季度
9月26号到12月26号为四季度
这个怎么写,求大佬
...全文
121 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
删库到跑路 2019-12-09
  • 打赏
  • 举报
回复
引用 1 楼 文盲老顾 的回复:
加个计算列

alter table tableName add 季度 as (case
when month(dateField)=12 and day(dateField)>=26 then '四季度'
when month(dateField)<3 then '四季度'
when month(dateField)=3 and day(dateField)<26 then '四季度'
when month(dateField)<6 then '一季度'
when month(dateField)=6 and day(dateField)<26 then '一季度'
when month(dateField)<9 then '二季度'
when month(dateField)=9 and day(dateField)<26 then '二季度'
when month(dateField)<12 then '三季度'
when month(dateField)=12 and day(dateField)<26 then '三季度'
else '' end
)


虽然不对,但是有思路了,感谢
文盲老顾 2019-12-09
  • 打赏
  • 举报
回复
加个计算列 alter table tableName add 季度 as (case when month(dateField)=12 and day(dateField)>=26 then '四季度' when month(dateField)<3 then '四季度' when month(dateField)=3 and day(dateField)<26 then '四季度' when month(dateField)<6 then '一季度' when month(dateField)=6 and day(dateField)<26 then '一季度' when month(dateField)<9 then '二季度' when month(dateField)=9 and day(dateField)<26 then '二季度' when month(dateField)<12 then '三季度' when month(dateField)=12 and day(dateField)<26 then '三季度' else '' end )

22,300

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧