I have a database table with rows that each contain a sequential index. I want to select groups of rows that are consecutive based upon this index column. For example, if I
I think this might work pretty efficiently (C# though):
int[] query = { 1, 3, 4, 5, 7, 9, 10, 11, 12, 15, 16 }; int count = 3; List> numbers = query .Where(p => query.Where(q => q >= p && q < p + count).Count() == count) .Select(p => Enumerable.Range(p, count).ToList()) .ToList();