mySQL ORDER BY DAYOFWEEK从今天开始

cut 发布于 4 天前 mysql 最后更新 4 天前 1 浏览

我有一个每周发生在不同日子的事件列表。 我希望我的查询返回按今天开始的星期几排序的结果。

'Meeting_Day' = Sunday,  Monday, Tuesday...
'Day_of_Week' = 1, 2, 3...
SELECT Meeting_Day, Day_of_Week, 
    Day_of_Week + (Day_of_Week - DAYOFWEEK(NOW())) as x FROM `meetings` ORDER BY x
这可能很简单,但我不赞成。
已邀请:

xporro

赞同来自:

我看了一下,发现我可以做得很好。

SELECT 
  *, 
  If(Day_of_Week < DAYOFWEEK(Now()), (Day_of_Week + 7), Day_of_Week) as SDAY 
FROM `meetings` 
ORDER BY SDAY