Rank the data, then subtract the value from the rank. GROUP on that
difference, finding the MIN (start of un-interrupted sequence) and MAX (end
of un-interrupted sequence) for each of these groups:
SELECT MIN(valueField) As start, MAX(valueField) AS ending
FROM somequery
GROUP BY valueField-Rank
To get the rank, many possibilities. Here is one (which will be the
'somequery' you will use here up) :
SELECT a.valueField, COUNT(*) AS rank
FROM table AS a INNER JOIN table AS b
ON a.valueField >=b.valueField
GROUP BY a.valueField
As example, with:
Table
valueField
1
2
3
5
6
7
8
9
11
12
The somequery (the last one) return:
valueField rank
1 1
2 2
3 3
5 4
6 5
7 6
8 7
9 8
11 9
12 10
And the first query will compute valueField-rank, and group on these
differences:
valueField rank
1 1 0
2 2 0
3 3 0
5 4 1
6 5 1
7 6 1
8 7 1
9 8 1
11 9 2
12 10 2
returning
start ending
1 3
5 9
11 12
since the un-interrupted sequences are from 1 to 3, 5 to 9, and 11 to 12
Vanderghast, Access MVP