SQL ORDER BY months starting with this month

前端 未结 6 1636
逝去的感伤
逝去的感伤 2021-01-24 21:23

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

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

Example

3
4
5
6
7
8
9
10
11
12
1         


        
6条回答
  •  -上瘾入骨i
    2021-01-24 21:55

    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
    

提交回复
热议问题