sql >> Base de Datos >  >> RDS >> Mysql

Encuentra habitación libre (sistema de reservas)

Aquí hay una consulta que mostrará las habitaciones NO LIBRES para un intervalo de fechas:

select room from bookings where
(arrival<'2011-03-12' and departure>='2011-03-12') -- overlap at the end
OR (arrival<='2011-03-10' and departure>'2011-03-10') -- overlap at the start
OR (arrival>='2011-03-10' and departure<='2011-03-12') -- complete overlap

Puedes usar esto con

select roomnumber from rooms where roomnumber not in (... as above ...)

para encontrar las habitaciones GRATIS