关于这个问题的延伸:
hotel reservation system SQL query: identify when one specific room is available
使用上面问题中列出的模式,我如何才能得到一个查询,该查询显示“为我连续两天查找本周可用的房间?”
最佳答案
只需加入可用性表两次
SELECT rooms.* FROM rooms, availability as a1, availability as a2
WHERE rooms.id = 123
AND a1.room_id = rooms.id
AND a2.room_id= rooms.id
AND a1.date_occupied + 1 = a2.date_occupied
或者,如果我们不想像1985年那样编写SQL:
SELECT rooms.* FROM rooms
JOIN availability a1 on a1.room_id = rooms.id
Join availability a2 on a2.room_id = rooms.id AND a1.date_occupied + 1 = a2.date_occupied
WHERE rooms.id = 123
关于mysql - SQL在预订系统中连续发现两天,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7748125/