0

我有下表:

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查询。

4

2 回答 2

0

试试这个查询

select * from table where (arrival_date<=travelStart AND arrival_date<=travelExpires) AND (departure_date>=travelStart AND departure_date<=travelExpires)
于 2013-02-14T05:56:21.600 回答
0

您的答案与BETWEENMySQL 中的运算符一样简单。这个怎么运作:

SELECT * from YourTable WHERE ( :arrivalDate BETWEEN travelStart AND travelExpires) AND ( :departureDate BETWEEN travelStart AND travelExpires )

您显然需要绑定:arrivalDateand:departureDate参数。

于 2012-11-28T10:33:15.277 回答