SQL ORDER BY 从本月开始 [英] SQL ORDER BY months starting with this month

查看:32
本文介绍了SQL ORDER BY 从本月开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个返回第 1-12 个月的查询.(INT)

I have a query that returns months 1-12. (INT)

有没有办法对从本月开始的结果进行排序?

Is there a way to order the results starting on this month desc?

例子

3
4
5
6
7
8
9
10
11
12
1
2

谢谢!

到这个月desc,我的意思是这个实际的月份.MONTH(GetDate())

By this month desc, I mean this actual month. MONTH(GetDate())

推荐答案

按顺序尝试简单的数学运算,如果月份小于当前加 12,不确定对性能会有什么影响...

Try simple maths in order by, if month is smaller then current add 12, not sure what will be the performance impact ...

Order By Case When month(dateColumn) < month(GetDate()) Then month(dateColumn) +12
ELSE month(dateColumn) END

这篇关于SQL ORDER BY 从本月开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆