简体   繁体   中英

Select Unbooked Room from Arrival and Departure Date

I have a table named room

id room
1 Room 1
2 Room 2

And a table named order

id id_room date_arrival date_departure
1 1 2018-09-13 2018-09-15
2 1 2018-09-27 2018-09-29

And when I choose date_arrival in 2018-09-14 and date_departure in 2018-09-20 I want an unbooked room that appears.

Try this: it's a overlapping range problem

http://sqlfiddle.com/#!9/9746d6/6

SELECT room.id, rname from
room  left join `roomorder`
on room.id=`roomorder`.id_room
and '2018-09-14' < date_departure AND '2018-09-20' > date_arrival

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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