SQLite 3 reference · Window Functions
SQLite CUME_DIST() Function
Return the cumulative distribution: the share of rows ordered at or before the current row, from just above 0 to 1.
SQLite 3 Since 3.25.0
Syntax
cume_dist() OVER (PARTITION BY ... ORDER BY ...)
Return value
A real number greater than 0 and at most 1.
Examples
SELECT name, salary, round(cume_dist() OVER (ORDER BY salary), 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
SELECT name, stock, round(cume_dist() OVER (ORDER BY stock), 2) AS cd
FROM products
WHERE category_id = 3;
Output
name | stock | cd Standing Desk Mat | 0 | 0.33 Desk Lamp | 12 | 0.67 Coffee Mug | 100 | 1
Version history
| Version | Change |
|---|---|
| SQLite 3.25.0 | Added |
In other languages
CUME_DIST()· PostgreSQL
Related
PERCENT_RANK()· Return a row's relative rank from 0 to 1: (rank - 1) / (rows in partition - 1).NTILE()· Split the rows of a window into N groups of nearly equal size and return each row's group number.- SQL Window Functions · tutorial