Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Reduce To Ranges aggregate function
Michel Cadot schreef:
> SQL> col Range format a20
> SQL> with
> 2 step1 as (
> 3 select id,
> 4 case
> 5 when nvl(lag(id) over (order by id),-1) != id-1 then id
> 6 end grp
> 7 from t),
> 8 step2 as (
> 9 select id,
> 10 max(grp) over (order by id) grp
> 11 from step1
> 12 )
> 13 select min(id)||decode(min(id),max(id),'','-'||max(id)) "Range"
> 14 from step2
> 15 group by grp
> 16 /
> Range
> --------------------
> 1-5
> 11-12
> 45
>
> 3 rows selected.
>
> Regards
> Michel Cadot
>
>
Love it! Beautiful!
-- Regards, Frank van Bortel Top-posting is one way to shut me up...Received on Thu Oct 19 2006 - 13:11:01 CDT
![]() |
![]() |