In PostgreSQL, we can use the cume_dist()
function to return the cumulative distribution of a value within a group of values.
It calculates this as follows: (the number of partition rows preceding or peers with current row) / (total partition rows).
The return value ranges from 1/N
to 1.