cume_dist
The result is the number of rows preceding or tied with the current row, divided by the total number of partition rows. Peers share the fraction at the end of their peer group.
Syntax
cume_dist() OVER ([PARTITION BY expression, ...] ORDER BY expression, ...)Arguments
The function takes no arguments. PARTITION BY starts an independent ranking for each group; without it, all selected rows form one partition. ORDER BY inside OVER determines the ranking order. A frame clause does not restrict the rows used for ranking.
Returned value
A REAL fraction greater than 0 and no greater than 1. The window order does not determine the final output order; use an outer ORDER BY to sort the result.
Example Ranking employee salaries
Ada and Grace have the same salary and therefore belong to the same peer group.
CREATE TABLE salaries (player TEXT, salary INTEGER);
INSERT INTO salaries VALUES ('Ada', 100), ('Grace', 100), ('Linus', 80), ('Sam', 60);SELECT player, salary,
cume_dist() OVER (ORDER BY salary DESC) AS result
FROM salaries
ORDER BY salary DESC, player
FORMAT csv;"Ada",100,0.5
"Grace",100,0.5
"Linus",80,0.75
"Sam",60,1.0See rank, dense_rank and row_number to compare tie handling, and window functions for partition and frame syntax.