I have one table that stores when a customer support employee is in a particular location and for what date. Each separate date is its own record.
I have a second table that stores a range of dates that customers have asked for onsite support.
I need to extract a list of dates that a given location does NOT have any support representation. All I need is the location and the date(s). I don't care which employee in that location or which customer has requested the support.
So in the sample data below, I need to see as my query results:
+--------+------------+ | London | 04/01/2019 | | London | 07/01/2019 | | Paris | 05/01/2019 | +--------+------------+
Table: Employee_Location
+----------+----------+------------+ | Employee | Location | Date | +----------+----------+------------+ | 1111 | London | 01/01/2019 | | 1111 | London | 02/01/2019 | | 1111 | London | 03/01/2019 | | 2222 | Paris | 01/01/2019 | | 2222 | Paris | 02/01/2019 | | 2222 | Paris | 03/01/2019 | | 2222 | Paris | 04/01/2019 | | 3333 | London | 05/01/2019 | | 3333 | Paris | 06/01/2019 | | 3333 | Paris | 07/01/2019 | | 4444 | London | 06/01/2019 | +----------+----------+------------+
Table: Customer_Request
+----------+----------+---------------+------------+ | Customer | Location | Request From | Request To | +----------+----------+---------------+------------+ | AAAA | London | 01/01/2019 | 06/01/2019 | | BBBB | Paris | 01/01/2019 | 06/01/2019 | | CCCC | London | 05/01/2019 | 07/01/2019 | +----------+----------+---------------+------------+
Here is my current code ...
select c.CALENDARDTM
from CALENDAR c, Employee_Location el
join Customer_Request cron el.location = cr.location
where c.CALENDARDTM NOT BETWEEN cr.RequestFrom and cr.RequestTo
and c.CALENDARDTM between '2019-01-01' AND '2019-01-07'