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

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

A real number greater than 0 and at most 1.

Examples

Share at or belowTry it yourself
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
Ties count togetherTry it yourself
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

VersionChange
SQLite 3.25.0Added

In other languages

Was this page helpful?