This method was first proposed by
Steve Kass of Drew University.
CREATE TABLE test1 (x int NOT NULL );
INSERT INTO test1 (x) VALUES(1);
INSERT INTO test1 (x) VALUES(2);
INSERT INTO test1 (x) VALUES(3);
INSERT INTO test1 (x) VALUES(6);
INSERT INTO test1 (x) VALUES(7);
INSERT INTO test1 (x) VALUES(8);
INSERT INTO test1 (x) VALUES(13);
INSERT INTO test1 (x) VALUES(16);
INSERT INTO test1 (x) VALUES(17);
Append an autonumber to each row.
ALTER table test1 add rowid autoincrement;
Perform the major query.
select min(x) as start,max(x) as end
from test1
group by x-rowid
order by 1;
start end
1 3
6 8
13 13
16 17
For Sql Server 2000 crosstabs and more check
out RAC @
www.rac4sql.net