我有一個表MySQL的ORDER BY最接近的兩個日期相結合,今天
... | reservation_from | reservation_to | ...
1 | 2016-05-13 10:00:00 | 2016-05-21 10:00:00 | ...
2 | 2016-05-13 20:00:00 | 2016-06-29 14:00:00 | ...
3 | 2016-05-01 10:00:00 | 2016-05-13 16:00:00 | ...
現在我已經訂購併獲得最接近天到今天保留。
例如,現在是2016-05-13,所以無論預定是開始還是結束,我都必須得到最接近當前時間的結果。我想訂購,象這樣的
... | reservation_from | reservation_to | ...
1 | 2016-05-13 10:00:00 | 2016-05-21 10:00:00 | ...
2 | 2016-05-01 10:00:00 | 2016-05-13 16:00:00 | ...
3 | 2016-05-13 20:00:00 | 2016-06-29 14:00:00 | ...
正如你看到的,第二個結果reservation_from
是05-01,但其reservation_to
小於3 reservation_from
我不知道如果我有問題明確,如果不是,請評論它,我應該指定更多。
除非你今天有些時間旅行者是2016-05-13;) –
[MySQL ORDER BY two fields condition]可能重複(http://stackoverflow.com/questions/32742718/mysql-order-by-two -fields-condition) – mitkosoft
你需要解釋你使用什麼邏輯來最接近今天,以及如何處理領帶破碎。 –