PostgreSQL 18 reference · Window Functions

PostgreSQL CUME_DIST() Function

Return the share of rows ordered at or before the current row (including ties), from just above 0 to 1.

PostgreSQL 18 Since 8.4

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

cume_dist() OVER (PARTITION BY ... ORDER BY ...)

Return value

double precision.

Examples

Share at or below
SELECT name, salary, round(cume_dist() OVER (ORDER BY salary)::numeric, 2) AS at_or_below
FROM employees
WHERE department = 'Sales';

Output

     name      | salary | at_or_below
---------------+--------+-------------
 Emma Novak    |  88000 |        0.33
 Diego Silva   |  90000 |        0.67
 Hannah Okafor | 150000 |        1.00
(3 rows)

Run this on your computer — see “Get Started” for setup.

Ties count together
SELECT title, round(cume_dist() OVER (ORDER BY title)::numeric, 2) AS cd
FROM employees
WHERE department = 'Engineering';

Output

        title        |  cd
---------------------+------
 CTO                 | 0.20
 Engineer            | 0.60
 Engineer            | 0.60
 Engineering Manager | 0.80
 Senior Engineer     | 1.00
(5 rows)

Run this on your computer — see “Get Started” for setup.

Version history

VersionChange
PostgreSQL 8.4Added

In other languages

Was this page helpful?