Assuming seconds always are '00.000': WITH cte AS ( SELECT Id, DATEADD(mi, -DATEPART(mi, TSDest) % 5, TSDest) TSDest, Value, ROW_NUMBER() OVER (PARTITION BY DATEADD(mi, -DATEPART(mi, TSDest) % 5, TSDest) ORDER BY TSDest ASC) rn FROM test ) SELECT Id, TSDest, Value FROM cte WHERE rn = 1 ORDER BY TSDest [fiddle](https://dbfiddle.uk/?rdbms=sqlserver_2017&fiddle=347db3b1fa26ea819b7979a6ec3d6ef8)