I have a client connection table which does not link directly to the associated session table, unfortunately. So, I need to find the OID for each C.ID where the C.ID's CONNECT and DISCONNECT fall-within an S.OID START and STOP. A row in C can only map to one OID.
For a table like:
Table C
ID CONNECT DISCONNECT
1 2022-09-01T00:07 2022-09-01T00:25
and a table like:
Table S
ID OID START FINISH STATE
1 1 2022-09-01T00:00 2022-09-01T00:02 STOP
2 2 2022-09-01T00:05 2022-09-01T00:08 PAUSE
3 2 2022-09-01T00:10 2022-09-01T00:18 PAUSE
4 2 2022-09-01T00:25 2022-09-01T00:38 STOP
5 5 2022-09-01T00:45 2022-09-01T00:58 STOP
C.ID = 1 "falls within" S.ID 2, 3, 4 which are all OID 2. To find this, first create table S' which is a list of the start and stop of each OID:
Table S'
OID START STOP STATE
1 2022-09-01T00:00 2022-09-01T00:02 STOP
2 2022-09-01T00:05 2022-09-01T00:38 STOP
5 2022-09-01T00:45 2022-09-01T00:58 STOP
Then for each row in C, find the OID with
OID.START <= C.CONNECT
AND
OID.STOP >= C.DISCONNECT
But how do I write this in SQL?