I have three tables:
CREATE TABLE activities (
activity varchar(20) Primary key
);
with data:
Table_Tennis1
Table_Tennis2
Table_Tennis3
and
CREATE TABLE times (
time varchar(5)
);
with data
09:00
10:00
11:00
12:00
13:00
14:00
15:00
16:00
17:00
18:00
19:00
20:00
and finally
CREATE TABLE planner (
day varchar(9) foreign key
time varchar(5) foreign key
activity varchar(20) foreign key
member bigint foreign key
);
and Primary Key = (day, time, activity)
with data
friday,09:00,Table_Tennis1,4
friday,10:00,Table_Tennis2,2
I was wondering it was possible to find out all the Table_Tennis rooms that are not being used at a certain time on a certain day, or all rooms that have not yet been booked on all times for one day.
so it should give me a result_set of
09:00, Table_Tennis2, Table_Tennis3
10:00, Table_Tennis1, Table_Tennis3
11:00, Table_Tennis1, Table_Tennis2, Table_Tennis3 ect ect
Or:
But not:
… because that would drop rooms with no entries for the day at all.
You might consider using
instead of
timeshould not be used as identifier. It is a reserved word in all SQL standards and a type name in PostgreSQL.Also, the data type
timeis a better fit for your purpose and occupies less space thanvarchar(5).And
instead of
The names of weekdays would let you cover one week. I assume you want more than that.