我有一個查詢,它使用BETWEEN
來顯示兩個日期之間的記錄。我的查詢需要顯示特定日期之間的arrival_date
和departure_date
。但查詢以某種方式顯示所有記錄。BETWEEN查詢不起作用
列類型是DATE
。
SELECT DISTINCT art.* FROM accommodation_room_types art
INNER JOIN accommodation_rooms ar ON art.id = ar.room_type
INNER JOIN accommodation a ON art.accommodation = a.id
WHERE a.id = 13 AND NOT EXISTS
(
SELECT 1 FROM booked_rooms br INNER JOIN booking b ON br.booking = b.id
WHERE br.room = ar.id
AND
(
b.arrival_date BETWEEN '2017-12-16' AND '2018-04-16'
)
OR
(
b.departure_date BETWEEN '2017-12-16' AND '2018-04-16'
)
)
即使我寫BETWEEN 'asd' AND 'asd'
,它仍然顯示所有記錄,不給任何格式錯誤。 我的查詢是否顯示兩個特定日期之間的記錄錯誤?
你需要的是更多的括號'WHERE X AND((B)OR(C))' – Ibu