简体   繁体   English

SQL在预订系统中连续发现两天

[英]SQL find two consecutive days in a reservation system

Extending on this question: hotel reservation system SQL query: identify when one specific room is available 扩展此问题: 酒店预订系统SQL查询:确定何时有特定房间可用

Using the schema listed in the question above, how can I have a query that says "Find me a room for 2 consecutive days thats available in this week?" 使用上面的问题中列出的架构,如何获得一个查询,内容为“连续两天为我找一个房间,这周可以住宿?”

Just join to the availability table twice 只需两次连接到可用性表

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

or, if we're not into writing SQL like its 1985: 或者,如果我们不喜欢像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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM