Beginner

679. JOIN with CUME_DIST

Use cumulative distribution to understand the relative position of JOINed records.

📘 Lesson 679 of 728 ⏱ 15 min 🎯 Advanced

CUME_DIST calculates the proportion of rows whose ordering value is less than or equal to the current row's value.

It helps determine how a value compares with the overall distribution of a dataset.

Determine the cumulative distribution of employee salaries.

SQL
SELECT
    e.EmployeeName,
    d.DepartmentName,
    e.Salary,
    CUME_DIST() OVER (
        ORDER BY e.Salary
    ) AS SalaryDistribution
FROM Employees e
INNER JOIN Departments d
    ON e.DepartmentID = d.DepartmentID;

Used in salary benchmarking, customer analytics, statistical reporting, and performance analysis.

  • CUME_DIST returns a value between 0 and 1.
  • It includes rows tied at the current value.
  • ORDER BY defines the distribution.
  • Useful for percentile-style analysis.
  • It differs from PERCENT_RANK in its treatment of cumulative position.
What does CUME_DIST measure?

It measures the proportion of rows with values less than or equal to the current row's ordered value.

Why use CUME_DIST?

It helps understand where a record falls within the cumulative distribution of a dataset.

Have you finished this lesson?

Introduction to SQL – All Lessons