473,387 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

deducing ranges in SQL

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
Feb 27 '06 #1
2 2962
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 :
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

Mar 21 '06 #2

"Oxnard" <ox***********@comcast.net> wrote in message
news:kc********************@comcast.com...
: 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
Mar 21 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
by: Alf P. Steinbach | last post by:
The C++ FAQ item 29.5 (this seems to be strongly related to C), at <url: http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.5> mentions that <quote> C++ guarantees a char is exactly one...
2
by: Ben O'Steen | last post by:
Scenario: ========= Using PyGame in particular, I am trying to write an application that will run a scripted timeline of events, eg at 5.5 seconds, play xxx.mp3 and put the image of a ball on...
2
by: Loribeth | last post by:
Hi All, I am working on a sub that will loop through a recordset and validate that the ranges are valid, ie no overlapping values - no gaps in the ranges. I am pretty sure I have the validation...
5
by: John Brock | last post by:
I am using VB.NET to read Excel workbooks which have various named ranges, some of which may not exist in any given workbook. I am trying to get a list of all the range names -- otherwise I need...
67
by: PC Datasheet | last post by:
Transaction data is given with date ranges: Beginning End 4/1/06 4/4/06 4/7/06 4/11/06 4/14/06 4/17/06 4/18/06 4/21/06 426/06 ...
9
by: Christoph Bartoschek | last post by:
Hi, some time ago I've read a paper that advised to store intervals on discrete values in the format [a;b[. One starts with the first element and finishes with one past the last one. However...
2
by: Oxnard | last post by:
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
3
by: Snedker | last post by:
Hi there, I really need some input of how to approach my little assignment. A customer wants to exclude all US IP-ranges from accessing part of his website. From...
7
by: guido | last post by:
Hi, I'm looking for a container class that can map whole ranges of keys to objects - something like std::map, but not only for individual values for the key, but for whole ranges. Example: I...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.