我有以下表格:
id travelStart travelExpires
1 2012-11-12 2013-01-31
1 2012-11-12 2013-01-31
以下是我的到达和离开日期:
arrival date: 2012-12-28
departure date : 2012-12-30
我想在travelStart和travelEnd日期之间检查到达和离开日期。如何为它编写mysql查询。
答案 0 :(得分:0)
您的答案是MySQL中BETWEEN
运算符最简单的解决方案。工作原理:
SELECT * from YourTable WHERE ( :arrivalDate BETWEEN travelStart AND travelExpires) AND ( :departureDate BETWEEN travelStart AND travelExpires )
您显然需要绑定:arrivalDate
和:departureDate
参数。
答案 1 :(得分:0)
尝试此查询
select * from table where (arrival_date<=travelStart AND arrival_date<=travelExpires) AND (departure_date>=travelStart AND departure_date<=travelExpires)