1
I have a table for service providers that informs the time they are not available.
id_prestador | id_pedido | hora_entrada | hora_saida
1 | abc1 | 2017-08-10 10:00:00 | 2017-08-10 14:00:00
2 | xpto2 | 2017-08-10 15:00:00 | 2017-08-10 18:00:00
I need to make a query to identify the providers that are available at the requested time, for example:
Time requested: the following: Check-in: 2017-08-10 08:00:00 Check-out: 2017-08-10 11:00:00
In this example he would bring the provider 2
Some light? Thank you very much!
Solved:
SELECT *
FROM fcs_prestadores_pedidos
WHERE hora_entrada not BETWEEN '2017-08-10 16:00:00' AND '2017-08-10 18:00:00'
AND hora_saida not between '2017-08-10 16:00:00' AND '2017-08-10 18:00:00'
What have been your attempts?
– Bsalvo
@Leandromarzullo: this is a classic case in SQL: intersection/overlap of intervals. On the web there are articles about it; search for
sql interval overlap
orsql range overlap
or similar terms.– José Diz