Skip to content

CUME_DIST

CUME_DIST() OVER ( [ PARTITION BY partition_expression ] ORDER BY sort_expression [ ASC | DESC ] )

Section titled “CUME_DIST() OVER ( [ PARTITION BY partition_expression ] ORDER BY sort_expression [ ASC | DESC ] )”
SELECT
product,
price,
CUME_DIST() OVER (ORDER BY price) as cum_dist
FROM
pricing_table;
| product | price | cum_dist |
|---------|-------|----------|
| A | 10 | 0.20 |
| B | 20 | 0.40 |
| C | 30 | 0.60 |
| D | 40 | 0.80 |
| E | 50 | 1.00 |

The CUME_DIST function computes the cumulative distribution of a value in a group of values in Oracle. It represents the percentage of rows that are less than or equal to the current row. The example calculates the cumulative distribution of prices in the pricing_table. For each row, it determines the percentage of prices that are lower or equal to the price in the current row.