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
Syntax
cume_dist() OVER (PARTITION BY ... ORDER BY ...)
Return value
double precision.
Examples
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.
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
| Version | Change |
|---|---|
| PostgreSQL 8.4 | Added |
In other languages
CUME_DIST()· SQLite
Related
PERCENT_RANK()· Return a row's relative rank from 0 to 1: (rank - 1) / (rows in partition - 1).- SQL Window Functions · tutorial