mysql hotel room availability

后端 未结 1 1917
感动是毒
感动是毒 2021-01-26 04:03

I have an availability table ind Mysql as follows:

id
room_id int(11)
avail_date date

For each room, there is a row for every date it is availa

1条回答
  •  北海茫月
    2021-01-26 04:26

    You want something like this:

    select room_id
    from availability a
    where avail_date between $start and $end
    group by room_id
    having count(*) = datediff($end, $start) + 1;
    

    The having clause is counting the number of rows during that period to see if it matches the number of days you need. This is "inclusive" logic, so if $start = $end, then it assumes you need the room on that date.

    0 讨论(0)
提交回复
热议问题