0
I am creating an agenda and need to perform a consultation of the interval between scheduled times.
Example:
Tabela: HORARIO_ATENDIMENTO
INICIO: 08:00
FIM: 18:00
Tabela: Agenda
ID: 1
HORA_INICIAL: 08:00
HORA_FINAL: 09:00
ID: 2
HORA_INICIAL: 10:00
HORA_FINAL: 11:00
In this scenario we have the schedules FREE: 09:00-10:00 and 11:00-18:00 and it is this information that I would like to view directly in the consultation. I searched here in the stack and did not find anything that gives me a north.
Assuming there is only 1 single day and performing a simple query, we would have:
SELECT id,hora_inicial,hora_final FROM agenda;
Resultado:
1 - 08:00 - 09:00
2 - 10:00 - 11:00
In short, I would like the returned data to be:
Resultado:
1 - 09:00-10:00
2 - 11:00-18:00
OBS: The end result I already got via code (PHP), but I would like to do this via SQL, because I have doubts about the performance.
If necessary, I can post the code, but since the doubt is not on it, but on how to build the "inverse" SQL let’s say so, I did not find it necessary to post.
Hello Felipe. Purely with SQL I did not imagine a way to achieve the expected result. I believe it is possible with a Procedure using a SQL Server (T-SQL) or Oracle (PLSQL). However I do not consider this date calculation "slow" within the application layer (PHP in the case);
– gmsantos
Your table should have all available schedules , working hours , a field signals whether the schedule is busy or not
– Motta
Thinking about your problem, and without having precedent and the like, I imagine this way. A schedule configuration table, where you would have the interval of each start/ start time.
– Tiedt Tech
The point is that the schedules are flexible and multiple of 1 minute, IE, the guy can schedule a time from 08:00 until 08:33 for example, ie, and highly flexible as to the schedule. I liked the question of the procedures I will be covering them. Thank you all for trying to help. :)
– Filipe L. Constante