0

not查询中,它仍然返回具有取消状态的房间名称,但是当我删除用于捕获日期的查询时,它status !='cancelled'正在工作。捕获日期的查询有问题吗?

$tbl_comp=mysql_query("SELECT * FROM roomlist 
WHERE type='$roomtype' and status = '1' 
and name NOT IN(select name from roomreservation where status  !='cancelled'

and 
arrival between '$arrival' and '$departure'
or departure between '$arrival' and '$departure'
or '$arrival'  between arrival and departure
or '$departure' between arrival and departure)");   
4

2 回答 2

0

查询的主要问题是status != 'cancelled'仅适用于日期测试的第一部分。

另一个问题是BETWEEN进行包容性比较,而您可能在另一预订出发的同一天接受新到货。您需要使用 < 和 > 而不是 比较日期BETWEEN。但是,内部查询中的测试可以简化为:

SELECT name FROM roomreservation
WHERE status != 'cancelled'    -- if cancelled: no conflict 
AND '$arrival' < departure     -- if $arrival >= departure: no conflict
AND '$departure' > arrival     -- if $departure <= arrival: no conflict  
于 2013-02-07T06:32:05.963 回答
0

它为我工作

SELECT
    *
FROM
    reservation
WHERE
    room = "3" AND
    status = 1 AND
    '2015-12-03' BETWEEN arrival AND departure OR
    '2015-12-06' BETWEEN arrival AND departure 
于 2015-12-02T09:13:28.363 回答