可预订的房间[酒店预订]

时间:2013-02-07 05:41:39

标签: sql

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)");   

2 个答案:

答案 0 :(得分: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  

答案 1 :(得分: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