If there are no gaps in id sequence:select a.Start ,a.End ,convert(varchar(8),dateadd(second,datediff(second,b.Start,a.End),0),114) as downtime from group_table3 as a left outer join group_table3 as b on b.ID=a.ID-1
If there are gaps:with cte as (select * ,row_number() over(order by ID) as rn from group_table3 )select a.Start ,a.End ,convert(varchar(8),dateadd(second,datediff(second,b.Start,a.End),0),114) as downtime from cte as a left outer join cte as b on b.rn=a.rn-1