I have a table that has records in the form(simplified): ID (int), startTime(DateTime), endTime(DateTime)
I want to be able to group records that “overlap” time duration by minute.
Ex:
1 - 12.00.AM - 12.10.AM ( duration here is 10 min)
2 - 12.05.AM - 12.07.AM (duration here is 2 minutes but is overlapping with record ID = 1 in minutes 05, 06, 07)
The result of such a query should be
minute 12.00 - record 1,
minute 12.01 - record 1,
...
minute 12.05 - record 1 + record 2,
minute 12.06 - record 1 + record 2,
minute 12.07 - record 1 + record 2
...
minute 12.10 - record 1
Note I use sql server (2005 uppwards)
This is one way to do it in Oracle (11g Release 2 as it includes the
LISTAGGfunction):The test data I used was:
And I get the following result: