In a SQL SERVER 2005 database, please suppose we have a table called RUNNING_COLA_IS_AFRICA.
This table has a unique varchar(50) field called RUNNING_ID.
We have 1 million records in this table.
I would like to write a query that, sorting by RUNNING_ID ASC, and stating a range of 50, produces an output similar to the following:
RUNNING_ID_START RUNNING_ID_END
000000 000103
000104 000767
000892 001492
001576 011222
012345 013579
This means that:
a) The number of the records between 000000 and 000103 is 50;
b) The number of the records between 000104 and 000767 is 50;
c) The number of the records between 000892 and 001492 is 50;
d) The number of the records between 001576 and 011222 is 50;
e) The number of the records between 012345 and 013579 is <= 50.
Of course, min(RUNNING_ID) = 000000 and max(RUNNING_ID) = 013579 because they are ordered by RUNNING_ID ASC.
How could I achieve this in SQL SERVER 2005?
Thank you in advance for your kind help.
1 Answer