Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Modern enterprise analytics frequently requires statistical distribution modeling:
MySQL 8.0 provides three powerful statistical distribution window functions: NTILE(), CUME_DIST(), and PERCENT_RANK().
NTILE(n) divides an ordered partition into n roughly equal buckets and assigns the bucket number (from 1 to n) to each row:
Rule: If the row count is not evenly divisible by n, earlier buckets receive the extra rows. (e.g., 10 rows into 4 buckets gives bucket sizes: 3, 3, 2, 2).
CUME_DIST() calculates the cumulative distribution of a value within a partition. It represents the proportion of rows with values less than or equal to the current row's value:
$$ ext{CUME_DIST} = rac{ ext{Number of rows with value} le ext{current value}}{ ext{Total rows in partition}}$$
A CUME_DIST of 0.80 indicates that 80% of students scored less than or equal to this student's score. The value ranges from > 0.0 to 1.0.
PERCENT_RANK() computes the relative rank of a row within a partition as a fraction between 0.0 and 1.0 using the formula:
$$ ext{PERCENT_RANK} = rac{ ext{Rank} - 1}{ ext{Total Rows} - 1}$$
PERCENT_RANK = 0.0.PERCENT_RANK = 1.0.| Function | Output Range | Key Characteristic | Common Use Case |
|---|---|---|---|
NTILE(n) | 1 to n (Integers) | Divides rows into equal discrete groups | Quartiles, deciles, tiering |
CUME_DIST() | > 0.0 to 1.0 (Float) | Fraction of rows $le$ current row | Cumulative probability, percentiles |
PERCENT_RANK() | 0.0 to 1.0 (Float) | Relative rank score based on (rank - 1)/(N - 1) | Standardized scoring, benchmarks |
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Value Boundary Functions: FIRST_VALUE, LAST_VALUE, NTH_VALUE | B-Tree vs Hash Index Data Structures |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.