Below is a record table, which contains different events info. How to get the duration of sum(eventB + eventC + eventD) - eventC - 2*eventD within the same date. (Refer below table)
NOTES:
- assume eventB only happen once a day, and there will be always one eventC and two eventD happen during the eventB
- there can be multiple eventC, eventD within a day
- need to calculate the: sum of the duration of (eventB + eventC + eventD) then minus the 1 eventC and 2 eventD duration, which happen between starttime and endtime of eventB.
table and MySQL details feel free to edit it
Basically, need to handle the overlap durations among eventC, enentD and eventB
Can someone please provide me with some code to handle the above case? Thanks a lot
Sample record table:
eventDate | event | eventStart | eventEnd | durations |
---|---|---|---|---|
2020-02-01 | eventB | 2020-02-01 09:10:25 | 2020-02-01 09:50:25 | 40 |
2020-02-01 | eventD | 2020-02-01 09:15:25 | 2020-02-01 09:20:25 | 5 |
2020-02-01 | eventC | 2020-02-01 09:30:25 | 2020-02-01 09:35:25 | 5 |
2020-02-01 | eventD | 2020-02-01 09:40:25 | 2020-02-01 09:45:25 | 5 |
2020-02-01 | eventC | 2020-02-01 09:55:25 | 2020-02-01 09:59:25 | 4 |
output for date 2020-02-01 will be 44 -->
sum(B + C + D) - C - 2*D = (40) + (5 + 4) + (5 + 5 ) - 5 - 5 -5 = 44
40 : sum of eventB durations
(5+4) is the sum of event C and so on,
-5 , - 5 and -5 is because the one eventC and two eventD happen during the eventB period.