|Oracle9i SQL Reference
Release 1 (9.0.1)
Part Number A90125-01
Functions, 29 of 166
"Analytic Functions" for information on syntax, semantics, and restrictions
CUME_DIST calculates the cumulative distribution of a value in a group of values. The range of values returned by
CUME_DIST is >0 to <=1. Tie values always evaluate to the same cumulative distribution value.
CUME_DISTcalculates, for a hypothetical row R identified by the arguments of the function and a corresponding sort specification, the relative position of row R among the rows in the aggregation group. Oracle makes this calculation as if the hypothetical row R were inserted into the group of rows to be aggregated over. The arguments of the function identify a single hypothetical row within each aggregate group. Therefore, they must all evaluate to constant expressions within each aggregate group. The constant argument expressions and the expressions in the
BYclause of the aggregate match by position. Therefore, the number of arguments must be the same and their types must be compatible.
CUME_DISTcomputes the relative position of a specified value in a group of values. For a row R, assuming ascending ordering, the
CUME_DISTof R is the number of rows with values lower than or equal to the value of R, divided by the number of rows being evaluated (the entire query result set or a partition).
The following example calculates the cumulative distribution of a hypothetical employee with a salary of $15,500 and commission rate of 5% among the employees in the sample table
SELECT CUME_DIST(15500, .05) WITHIN GROUP (ORDER BY salary, commission_pct) "Cume-Dist of 15500" FROM employees; Cume-Dist of 15500 ------------------ .972477064
The following example calculates the salary percentile for each employee in the purchasing area. For example, 40% of clerks have salaries less than or equal to Himuro.
SELECT job_id, last_name, salary, CUME_DIST() OVER (PARTITION BY job_id ORDER BY salary) AS cume_dist FROM employees WHERE job_id LIKE 'PU%'; JOB_ID LAST_NAME SALARY CUME_DIST ---------- ------------------------- ---------- ---------- PU_CLERK Colmenares 2500 .2 PU_CLERK Himuro 2600 .4 PU_CLERK Tobias 2800 .6 PU_CLERK Baida 2900 .8 PU_CLERK Khoo 3100 1 PU_MAN Raphaely 11000 1