cume_dist
Computes the cumulative distribution of a value within a group of values, i.e., the percentage of rows with values less than or equal to the current row's value. Can be used to determine relative standing of a value within a partition.
Syntax
The default and required window frame definition is RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING.
For more detail on window function syntax see: Window Functions - Syntax.
Returned value
- The relative rank of the current row. The return type is Float64 in the range [0, 1]. Float64.
Example
The following example calculates the cumulative distribution of salaries within a team:
Query:
Result:
Implementation Details
The cume_dist() function calculates the relative position using the following formula:
Rows with equal values (peers) receive the same cumulative distribution value, which corresponds to the highest position of the peer group.