I may have simplified your request, but consider the following
Declare @YourTable table (ID int,Date datetime) Insert Into @YourTable values ( 1,'2016-01-29 10:27:25.603'), ( 2,'2016-01-29 10:27:25.620'), ( 3,'2016-01-29 10:27:25.637'), ( 4,'2016-01-29 10:27:25.653'), ( 5,'2016-01-29 10:27:25.723'), ( 6,'2016-01-29 10:27:34.647'), ( 7,'2016-01-29 10:27:34.667'), ( 8,'2016-01-29 10:27:34.680'), ( 9,'2016-01-29 10:27:34.690'), (10,'2016-01-29 10:27:34.707') Declare @BatchSecondsGap int = 2 -- Seconds Between Batches Declare @MinObservations int = 5 -- Batch must n or greater ;with cte as ( Select *,Cnt = sum(1) over (Partition By Batch) From ( Select *,Batch = sum(Flg) over (Order By Date) From ( Select ID,Date ,Flg = case when DateDiff(SECOND,Lag(Date,1,null) over (Order By Date),Date)> =@BatchSecondsGap then 1 else 0 end ,MS = case when DateDiff(SECOND,Lag(Date,1,Date) over (Order By Date),Date)> =@BatchSecondsGap then 0 else DateDiff(MILLISECOND,Lag(Date,1,Date) over (Order By Date),Date) end From @YourTable ) A ) B ) Select Title = 'Total' ,DateR1 = min(Date) ,DateR2 = max(Date) ,BatchCnt = count(Distinct Batch) ,TransCnt = count(*) ,MS_Ttl = sum(MS) ,MS_Avg = avg(MS*1.0) ,MS_Std = stdev(MS) From cte Where Cnt> =@MinObservations Union All Select Title = concat('Batch ',Batch) ,DateR1 = min(Date) ,DateR2 = max(Date) ,BatchCnt = count(Distinct Batch) ,TransCnt = count(*) ,MS_Ttl = sum(MS) ,MS_Avg = avg(MS*1.0) ,MS_Std = stdev(MS) From cte Where Cnt> =@MinObservations Group By Batch
Returns

The following figure shows that you will not be punished for the time between batches, so it will become a simple aggregation for the final results
