SQL ORDER BY months starting with this month

前端 未结 6 1690
逝去的感伤
逝去的感伤 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条回答
  •  难免孤独
    2021-01-24 22:12

    If you do not add years, it is impossible. The reasoning is because there is no way to tell which January or any month came first.

    The only solution you have to to simply order them by YEAR first, then by MONTH.

    So unless you change the field into a DATE format or include a YEAR column, you can't do anything. Unless you want to arrange them by ID; which was entered first.

    So in short: No YEAR = no way.

提交回复
热议问题