Query to bring BETWEEN data

0

Good morning, folks, I'm going around with a query that would seem simple but I can not find it back. I am developing a reservation system in which fractional every 00:30 minutes and reserve by rank of 01:00:00 or 01:30:00 I have a reservation table id, date, time, status with all possible hours with a state 0 for free and 1 for reserved. The issue is that if I have an example reserve from 10:00:00 to 11:00 and one from 12:00:00 to 13:00:00 and I want to do one from 11:30 to 13:30, he brings it to me as if it was correct being part of that range reserved. Well I hope you understand if you can give me a hand I'll thank you very much

and I have the following query

SELECT *, ADDTIME('hora', '01:00:00') as hasta 
FROM 'reservas' 
WHERE ('hora' BETWEEN hora and  ADDTIME('hora', '01:00:00'))
AND 'dia' = '2017-11-29' 
AND 'estado' = '1'
    
asked by Hugo Marcelo 28.11.2017 в 14:32
source

1 answer

0

People thank you very much I solved it in the following way, counting how many employees are within that time range if there is one does not bring it I leave it in case someone needs it for something

SELECT *, ADDTIME('hora', '01:00:00') as hasta
  FROM 'reservas' r1
 WHERE ( (select count(*)
            from reservas r2
           where r2.hora >= r1.hora
             and r2.hora <= ADDTIME(r1.hora, '01:00:00')
             AND r2.dia = '2017-11-29'
             AND r2.estado = 0 ) = 0 ) 
  AND r1.dia = '2017-11-29'
  AND r1.estado = 1
    
answered by 28.11.2017 в 16:10