Class| Value
-------------
A | 1
A | 2
A | 3
A | 10
B | 1
I am not sure whether it is practical to achieve this using SQL. If the difference of values are less than 5 (or x), then group the rows (of course with the same Class)
Expected result
Class| ValueMin | ValueMax
---------------------------
A | 1 | 3
A | 10 | 10
B | 1 | 1
For fixed intervals, we can easily use "GROUP BY". But now the grouping is based on nearby row's value. So if the values are consecutive or very close, they will be "chained together".
Thank you very much
Assuming MSSQL
These give the correct result, using the fact that you must have the same number of group starts as ends and that they will both be in ascending order.
Method 1 Using CTE and row offsets
** Method 2 Inline views using not exists **
In both methods I use a select distinct to begin because if you have a dulpicate entry at a group start or end things go awry without it.