0
使用此查詢我會找到所有可用的公寓。 所有可用的公寓都沒有預訂ID。獲取可用公寓
我想要的:當有一個預約ID和狀態將被取消我也希望公寓露面,但我不知道如何...
SELECT a.id, a.num_persons, a.rating, a.lat, a.lng, a.street, a.number
,c.title, c.introduction, c.text, c.area, c.long_term_rental, c.beds
, c.features ,c.services_and_equipment, c.terms_and_conditions
, m.url
FROM appartments AS a
INNER JOIN appartments_content AS c on c.parent_id = a.id
INNER JOIN meta AS m on m.id = c.meta_id
LEFT JOIN appartments_bookings AS b
ON (b.appartment_id = a.id
AND NOT ((? > b.departure) OR (? < b.arrival)))
-- this ? = arrival that ? = departure
WHERE b.id IS NULL
AND c.language = ?
AND a.hidden = ?
AND a.publish_on <= ?
AND a.city_id = ?
AND a.num_persons >= ?
ORDER BY a.num_persons ASC, a.publish_on DESC
LIMIT ? OFFSET ?'
我加了這一點:
AND b.status != ? OR NOT ((? >= b.departure) OR (? < b.arrival))) WHERE b.order_id IS NULL
但是這不起作用,我得到的結果。
也許你應該在你的問題中包含appartments,appartments_content和appartments_bookings的表定義。 – jan
給出了數據結構,我今天在家裏忘了我的水晶地球儀:P –