Group close numbers
问题 I have a table with 2 columns of integers. The first column represents start index and the second column represents end index. START END 1 8 9 13 14 20 20 25 30 42 42 49 60 67 Simple So far. What I would like to do is group all the records that follow together: START END 1 25 30 49 60 67 A record can follow by Starting on the same index as the previous end index or by a margin of 1: START END 1 10 10 20 And START END 1 10 11 20 will both result in START END 1 20 I'm using SQL Server 2008 R2.