Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.tools -> select question
I have a table with varchar2(5) column, for example:
> select spqmc from proba;
spqmc
(Unfortunatelly there is much more rows there, about 500).
I need one select that would give me continuos ranges. I mean
> select r_from, r_to from (some magic select);
r_from r_to
10000 10002 10004 10005 10007 10007
I came up with one, terribly slow, solution. Maybe it can be done in some other way.
Here is what I got:
SELECT A.SPQMC OD1 , B.SPQMC DO1
FROM PROBA A, PROBA B
WHERE
B.SPQMC - A.SPQMC =
(SELECT (COUNT(*)-1) FROM PROBA LICZ WHERE LICZ.SPQMC >= A.SPQMC AND SPQMC <= B.SPQMC)AND
10000 10000 10000 10001 10000 10002 10001 10001 10001 10002 10002 10002 10004 10004 10004 10005 10005 10005 10007 10007
2) I restrict the list "from the right" (about 1 second for 100 rows):
SELECT OD1, MAX(DO1) DO2
FROM (
1)
)
GROUP BY OD1
od1 do2
10000 10002 10001 10002 10002 10002 10004 10005 10005 10005 10007 10007
3) Now I restrict the list "from the left" (about 1 second for 100 rows):
SELECT MIN(OD1) od1, DO2
FROM (
2)
)
GROUP BY Do2
od1 do2
10000 10002 10004 10005 10007 10007
I use Oracle 8.1.6. Is there any trick here that could solve or speed up this thing? Received on Mon Jul 23 2001 - 08:39:25 CDT