Unix Technical Forum

eliminating gaps

This is a discussion on eliminating gaps within the Oracle Miscellaneous forums, part of the Oracle Database category; --> hi all i have a table with two cols A and B and following values.. A B 1 10000 ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database > Oracle Miscellaneous

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 11:15 AM
eokumus79@gmail.com
 
Posts: n/a
Default eliminating gaps

hi all
i have a table with two cols A and B
and following values..


A B
1 10000
1 10001
1 10002
1 10006
1 10007
2 10008
2 10009
2 10010
2 10011
2 10012
2 10015
3 10021
3 10022
3 10023
3 10031
3 10032
3 10033
3 10034
3 10035
4 10041
4 10042
4 10044

i want to get following output

A B C
1 10000 10002
1 10006 10007
2 10008 10015
3 10021 10023
3 10031 10035
4 10041 10042
4 10044 10044

could anyone help me ?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 11:15 AM
Dieter Noeth
 
Posts: n/a
Default Re: eliminating gaps

eokumus79@gmail.com wrote:

> A B
> 1 10000
> 1 10001
> 1 10002
> 1 10006
> 1 10007
> 2 10008
> 2 10009
> 2 10010
> 2 10011
> 2 10012
> 2 10015
> 3 10021
> 3 10022
> 3 10023
> 3 10031
> 3 10032
> 3 10033
> 3 10034
> 3 10035
> 4 10041
> 4 10042
> 4 10044
>
> i want to get following output
>
> A B C
> 1 10000 10002
> 1 10006 10007
> 2 10008 10015
> 3 10021 10023
> 3 10031 10035
> 4 10041 10042
> 4 10044 10044


select
a,
min(b),
max(b)
from
(
select
a - rank() over (partition by A order by b asc) as grp,
a
from mytab
) dt
group by a, grp
order by 1,2;

If a/b is not unique, replace rank with dense_rank...

Dieter
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 11:15 AM
Dieter Noeth
 
Posts: n/a
Default Re: eliminating gaps

Dieter Noeth wrote:

> select
> a,
> min(b),
> max(b)
> from
> (
> select
> a - rank() over (partition by A order by b asc) as grp,
> a
> from mytab
> ) dt
> group by a, grp
> order by 1,2;


Sorry, of course it's:

select
a,
min(b),
max(b)
from
(
select
b - rank() over (partition by A order by b asc) grp,
a,
b
from mytab
) dt
group by a, grp
order by 1,2;

Dieter
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-08-2008, 11:15 AM
eokumus79@gmail.com
 
Posts: n/a
Default Re: eliminating gaps

thank you very much. you are great

Dieter Noeth wrote:
> Dieter Noeth wrote:
>
> > select
> > a,
> > min(b),
> > max(b)
> > from
> > (
> > select
> > a - rank() over (partition by A order by b asc) as grp,
> > a
> > from mytab
> > ) dt
> > group by a, grp
> > order by 1,2;

>
> Sorry, of course it's:
>
> select
> a,
> min(b),
> max(b)
> from
> (
> select
> b - rank() over (partition by A order by b asc) grp,
> a,
> b
> from mytab
> ) dt
> group by a, grp
> order by 1,2;
>
> Dieter


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:31 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com