Skip to content
Advertisement

Aggregation Of Overlapping Events Problem

I have a list of 1 to N Shifts Each shift can have N events with their own start and end date I want to Aggregate and salami slice these into a common aggregate event, that changes whenever the shifts overlap & intersect.

So

Thus a user can click on one of the aggregate events and see all the staff that are on at that moment in time.

So the sections above would show

  1. All staff in shift 1
  2. All Staff in shift 1 & 2
  3. All Staff in shift 2 & 3
  4. All Staff in shift 3
  5. All Staff in shift 4

I select all the events I the use a CTE to get all the possible allocation units of time between the first event and the last event.

Then I struggle to take this further to group and aggregate these into single these aggregate blocks.

Any ideas?

Advertisement

Answer

You can combine two pieces of information — all times for the shifts and when peoples particular shifts are.

Let me assume you have a single table called shifts. Then you can do:

If you have a particular time, it is simpler to do:

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement