René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback
 

cume_dist [Oracle SQL analytic function]

cume_dist returns a number between 0 and 1.
create table cd_tab (n number);

insert into cd_tab values(null);
insert into cd_tab values(   1);
insert into cd_tab values(   2);
insert into cd_tab values(   3);
insert into cd_tab values(   4);
insert into cd_tab values(   5);
insert into cd_tab values(  10);
insert into cd_tab values(  10);
insert into cd_tab values(  10);
insert into cd_tab values(  10);
insert into cd_tab values( 100);

select n,
       cume_dist ( ) over (order by n) cume_dist,
       count     (1) over (order by n range unbounded preceding) /
       count     (*) over () calclated
from   cd_tab;
         N  CUME_DIST  CALCLATED
---------- ---------- ----------
         1 .090909091 .090909091
         2 .181818182 .181818182
         3 .272727273 .272727273
         4 .363636364 .363636364
         5 .454545455 .454545455
        10 .818181818 .818181818
        10 .818181818 .818181818
        10 .818181818 .818181818
        10 .818181818 .818181818
       100 .909090909 .909090909
                    1          1