Hi.
I would like to learn how to create queries with time type columns.
I’m attaching an ultra-simplified database containing just one table (with ~ 100 rows):
CREATE TABLE T_SLOTS (
SLO_ID INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1) NOT NULL,
OPE_ID INTEGER NOT NULL, -- operator
RES_ID INTEGER NOT NULL, -- resident
DAY_ID TINYINT NOT NULL, -- from 1 (monday) to 7 (sunday)
HOU_BEG TIME NOT NULL, -- hourly begin
HOU_END TIME NOT NULL, -- hourly end
CONSTRAINT PK_SLO_ID PRIMARY KEY (SLO_ID)
);
Operators work for residents. In the complete database, I have an acurate overview of each schedule, but what I’d like is to obtain the available time slots, for example, between 08:00:00 and 18:00:00, for a given operator, according to the slots already filled with, in addition, possibly, time slots where the operator doesn’t want to work.
Example:
operator 1 works the monday :
- at resident 1 from 08:00 to 10:00
- at resident 2 from 10:00 to 12:00
- at resident 3 from 15:00 to 17:00
The result of the query would therefore be from 12:00 to 15:00 and from 17:00 to 18:00.
But taking into account that the operator doesn’t want to work between 12:00 and 13:30 → the result would be from 13:30 to 15:00 and from 17:00 to 18:00.
I think you should use INTERVAL and/or EXCEPT, but I’ve never used them before.
Thanks.
dbPrimus20250625.odb (6,1 Ko)