Order by day_of_week in MySQL

后端 未结 10 2122
一向
一向 2020-12-14 04:15

How can I order the mysql result by varchar column that contains day of week name?

Note that MONDAY should goes first, not SUNDAY.

相关标签:
10条回答
  • 2020-12-14 05:01

    Found another way, your can reverse order bye week

    ORDER BY date_format(date_name, '%w') DESC;
    
    0 讨论(0)
  • 2020-12-14 05:02

    ... ORDER BY date_format(order_date, '%w') = 0, date_format(order_date, '%w') ;

    0 讨论(0)
  • 2020-12-14 05:03

    Found another way that works for me:

    SELECT LAST_NAME, HIRE_DATE, TO_CHAR(HIRE_DATE, 'fmDAY') as 'Day' FROM EMPLOYEES
    ORDER BY TO_CHAR(HIRE_DATE, 'd');    
    

    Hope it helps

    0 讨论(0)
  • 2020-12-14 05:06

    If you try this, it should work:

    SELECT ename, TO_CHAR(hiredate, 'fmDay') as "Day" 
    FROM my_table
    ORDER BY MOD(TO_CHAR(hiredate, 'D') + 5, 7)
    
    0 讨论(0)
提交回复
热议问题