This is my own "Peso 2";WITH cteAS ( SELECT seq_nbr, d, ROW_NUMBER() OVER (ORDER BY seq_nbr) / 2 AS theGrp FROM [Sample] CROSS JOIN ( VALUES (0), (1) ) AS x(d))SELECT MIN(seq_nbr) AS col1, MAX(seq_nbr) AS col2FROM cteGROUP BY theGrpHAVING MAX(d) = 1
And here is the statistics between your #2 and my #2 when using more sample data, or example 2514 records.-- Peso 2 (my own version)Table 'Worktable'. Scan count 0, logical reads 0, physical reads 0.Table 'Sample'. Scan count 1, logical reads 7, physical reads 0. SQL Server Execution Times: CPU time = 0 ms, elapsed time = 53 ms.-- Ms65g #2Table 'Worktable'. Scan count 0, logical reads 0, physical reads 0.Table 'Sample'. Scan count 1, logical reads 14, physical reads 0. SQL Server Execution Times: CPU time = 0 ms, elapsed time = 69 ms.
N 56°04'39.26"E 12°55'05.63"