在MySQL中按day_of_week排序 [英] Order by day_of_week in MySQL

查看:79
本文介绍了在MySQL中按day_of_week排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何按包含星期几名称的varchar列排序mysql结果?

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

请注意,MONDAY应该排在第一位,而不是SUNDAY.

Note that MONDAY should goes first, not SUNDAY.

推荐答案

要么按照Williham Totland的建议重新设计列,要么进行一些字符串解析以获取日期表示形式.

Either redesign the column as suggested by Williham Totland, or do some string parsing to get a date representation.

如果仅 列包含星期几,则可以执行以下操作:

If the column only contains the day of week, then you could do this:

ORDER BY FIELD(<fieldname>, 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY', 'SUNDAY');

这篇关于在MySQL中按day_of_week排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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