2016-09-26 76 views
0

我有一個每週發生在不同日子的事件列表。 我希望我的查詢返回按今天開始的星期幾排序的結果。mySQL ORDER BY DAYOFWEEK從今天開始

'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 

這可能很簡單,但我不是專業人士。

回答

0

我看了一會兒,發現我可以做得很好。

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