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 –