All the complexity results from the overlapping intervals.
If we pack the intervals so there are no overlaps, the solution is a straightforward group and sum.
The following code uses Itzik Ben-Gan's ...
Here is a solution that uses Run Length Encoding to compress overlapping time ranges -
SCHEMA AND DESIRED OUTPUT
DROP TABLE IF EXISTS dbo.EventTimes;
CREATE TABLE dbo.EventTimes
EventTimeKeyId INT ...
I tweaked the query that Caleb provided to ensure we always stitch back the phrase in the order it was split and in order to do that i'm using OPENJSON split trick suggested by Aaron in an article. ...