我有一个表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
你需要解释你使用什么逻辑来最接近今天,以及如何处理领带破碎。 –