dbTalk Databases Forums  

deducing ranges in SQL

comp.databases.oracle comp.databases.oracle


Discuss deducing ranges in SQL in the comp.databases.oracle forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Oxnard
 
Posts: n/a

Default deducing ranges in SQL - 02-26-2006 , 10:39 PM






Oracle 9.2.0.6 in AIX

I am trying to find ranges and where the range ends for each d_no:
The increment of val is one

My example is:

select * from t1

d_no val
1 20
1 21
1 22
1 23
1 25
1 1503
1 1504
3 502
3 503
3 504
3 600

I am trying to come up with an SQL which would produce an output of

d_no the_range
1 20-23
1 25
1 1503-1504
3 502-504
3 600

I have tried using some of the analytic functions and got close with lead
but not quite. I could do a cursor in
PL/SQL but the table is so huge it takes way to long. In fact I did do this
on a small table. It worked just fine.
Also what I am showing as a table is really an in-line view of a couple of
tables I have joined.

Any ideas would really be helpful

Thank you



Reply With Quote
  #2  
Old   
Bertrand Guillaumin
 
Posts: n/a

Default Re: deducing ranges in SQL - 03-21-2006 , 03:34 PM






Try something like this :

SELECT D_NO , to_char(Min(Val)) || '-' || to_char(Max(Val))
Group By D_No

Hope it will help.

Oxnard a écrit :
Quote:
Oracle 9.2.0.6 in AIX

I am trying to find ranges and where the range ends for each d_no:
The increment of val is one

My example is:

select * from t1

d_no val
1 20
1 21
1 22
1 23
1 25
1 1503
1 1504
3 502
3 503
3 504
3 600

I am trying to come up with an SQL which would produce an output of

d_no the_range
1 20-23
1 25
1 1503-1504
3 502-504
3 600

I have tried using some of the analytic functions and got close with lead
but not quite. I could do a cursor in
PL/SQL but the table is so huge it takes way to long. In fact I did do this
on a small table. It worked just fine.
Also what I am showing as a table is really an in-line view of a couple of
tables I have joined.

Any ideas would really be helpful

Thank you



Reply With Quote
  #3  
Old   
Mark C. Stock
 
Posts: n/a

Default Re: deducing ranges in SQL - 03-21-2006 , 04:40 PM




"Oxnard" <oxnardNO_SPAM (AT) comcast (DOT) net> wrote

: Oracle 9.2.0.6 in AIX
:
: I am trying to find ranges and where the range ends for each d_no:
: The increment of val is one
:
: My example is:
:
: select * from t1
:
: d_no val
: 1 20
: 1 21
: 1 22
: 1 23
: 1 25
: 1 1503
: 1 1504
: 3 502
: 3 503
: 3 504
: 3 600
:
: I am trying to come up with an SQL which would produce an output of
:
: d_no the_range
: 1 20-23
: 1 25
: 1 1503-1504
: 3 502-504
: 3 600
:
: I have tried using some of the analytic functions and got close with lead
: but not quite. I could do a cursor in
: PL/SQL but the table is so huge it takes way to long. In fact I did do
this
: on a small table. It worked just fine.
: Also what I am showing as a table is really an in-line view of a couple of
: tables I have joined.
:
: Any ideas would really be helpful
:
: Thank you
:
:

what version of oracle and what have you tried?

++ mcs



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.