我尝试创建一个查询,显示签入和结帐日期之间的可用酒店。此外,当我预订特定房间时,我将其预订栏设置为1.这意味着,当结账日期出现在现实生活中时,触发功能会将预订列设置为0.
如果预订酒店的所有房间(预订= 1)并且这些房间的登记结账日期是特定日期(登记结账输入),则不要将该酒店列入清单。我的查询没有显示我想要的结果。
查询:输入:国家/地区(州),签到和结帐。
SELECT DISTINCT a.* FROM accommodation a INNER JOIN cb_states s ON a.state = s.id
INNER JOIN accommodation_rooms ar ON a.id = ar.accommodation
WHERE state = 1 AND a.id NOT IN
(
SELECT 1 FROM booking b
WHERE
(
(b.arrival_date BETWEEN '2017-11-16' AND '2018-03-16')
OR
(b.departure_date BETWEEN '2017-11-16' AND '2018-03-16')
)
)
当我运行查询时,它总是显示所有酒店,无论日期。如果我写... WHERE ar.booked = 0 AND state = 1 AND a.id NOT IN...
,那么它不显示住宿ID 13,但是当我更改日期时它也没有显示。
答案 0 :(得分:1)
您的查询存在多个问题:
NOT IN
列表中包含SELECT 1
。这并没有为NOT IN
列表提供多种选择。所以:
SELECT DISTINCT a.*
FROM accommodation a INNER JOIN
cb_states s
ON a.state = s.id INNER JOIN
accommodation_rooms ar
ON a.id = ar.accommodation
WHERE s.state = 1 AND
a.id NOT IN (SELECT br.accommodation_room
FROM booking b JOIN
booked_room br
ON b.?? = br.??
WHERE b.arrival_date <= '2018-03-16' AND
b.departure_date >= '2017-11-16'
);