add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
with data as
(
select 'A' process, 1 id, cast('2018-07-24 00:00:00' as datetime2) StartTime, cast('2018-07-24 00:02:54' as datetime2) EndTime
union all
select 'A' , 2 , '2018-07-24 00:00:16' , '2018-07-24 00:02:55'
union all
select 'A' , 3 , '2018-07-24 11:12:42' , '2018-07-24 11:15:10'
union all
select 'A' , 4 , '2018-07-24 00:00:16' , '2018-07-24 00:02:55'
)
select t.process, sum(datediff(second, t.StartTime, t.EndTime))
from
(
select distinct d1.process, min(d2.StartTime) StartTime, max(d2.EndTime) EndTime
from data d1
left join data d2 on d2.EndTime > d1.StartTime and d2.StartTime < d1.EndTime
group by d1.process, d1.id
) t
group by t.process
process (No column name)
A 323