Row Access Inside a Partition
Expand your knowledge of window functions with insights into row access inside a partition.
We'll cover the following
Using a window function entails a window specification. However, all four components of the window specification are optional, particularly the frame specification. For some window functions (e.g., CUME_DIST()
, LEAD()
, and RANK()
), a frame specification is not necessary and is even ignored. That is because these window functions already imply the partition as their frame. That is also the case for the various window functions we discuss below, as they directly access rows within the partition.
Cumulative distribution
For an ordered set of values, the cumulative distribution gives the fraction of values within the set that is less than or equal to the value in the current row. Hence, the cumulative distribution yields values from 0 to 1. In MySQL, CUME_DIST()
computes the cumulative distribution of the values in a column. This computation only makes sense if the corresponding partition is ordered with ORDER BY
. Otherwise, the cumulative value distribution for each row value is 1. For the demonstration of CUME_DIST()
, we return to our running example of car models:
Get hands-on with 1400+ tech skills courses.