July 2010
Intermediate to advanced
840 pages
16h 33m
English
The goal is to take a list of numbers and condense them into contiguous ranges. Show the high and low values for each range; if the range has one number, then the high and low values will be the same. This answer is due to Steve Kass.
SELECT MIN(i) AS low, MAX(i) AS high
FROM (SELECT N1.i, COUNT(N2.i) - N1.i
FROM Numbers AS N1, Numbers AS N2
WHERE N2.i <= N1.i
GROUP BY N1.i)
AS N(i, gp)
GROUP BY gp;Read now
Unlock full access