What do PERCENT_RANK() and CUME_DIST() compute, and how do they differ from each other and from NTILE()?

Quick Overview

Asks what the SQL window functions PERCENT_RANK, CUME_DIST and NTILE return for each row of an ordered partition. Tests whether you know their formulas, their value ranges and how each one handles tied values when you build percentile filters or buckets.

What do PERCENT_RANK() and CUME_DIST() compute, and how do they differ from each other and from NTILE()?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

`PERCENT_RANK()`, `CUME_DIST()` and `NTILE()` are SQL window functions that describe where a row sits within an ordered partition. What do `PERCENT_RANK()` and `CUME_DIST()` compute, and how do they differ from each other and from `NTILE()`? ```hint Work an example with ties Take the ordered values 10, 20, 20, 30, 30 and compute each function by hand. Watch the rows that share a value, and check what the largest value gets. ``` ### What a Strong Answer Covers - The formula behind `PERCENT_RANK()` and `CUME_DIST()`, and the range of values each one can return - How each of the three functions treats tied rows - What `NTILE(n)` returns and how it sizes buckets when the row count does not divide evenly - When a continuous fraction is the right tool and when a bucket label is ### Follow-up Questions - What does `PERCENT_RANK()` return for a partition with a single row? - How would you compute `PERCENT_RANK()` and `CUME_DIST()` without window functions? - You need deciles where tied values always share a decile. How would you build them, given that `NTILE(10)` can split ties? - How does `CUME_DIST()` relate to `PERCENTILE_DISC()`?

Overview: Asks what the SQL window functions PERCENT_RANK, CUME_DIST and NTILE return for each row of an ordered partition. Tests whether you know their formulas, their value ranges and how each one handles tied values when you build percentile filters or buckets.

General logo
General
Nov 25, 2026
mediumData ScientistOtherData Manipulation (SQL/Python)
0
0

PERCENT_RANK(), CUME_DIST() and NTILE() are SQL window functions that describe where a row sits within an ordered partition.

What do PERCENT_RANK() and CUME_DIST() compute, and how do they differ from each other and from NTILE()?

What a Strong Answer Covers Guidance

  • The formula behind PERCENT_RANK() and CUME_DIST() , and the range of values each one can return
  • How each of the three functions treats tied rows
  • What NTILE(n) returns and how it sizes buckets when the row count does not divide evenly
  • When a continuous fraction is the right tool and when a bucket label is

Follow-up Questions Guidance

  • What does PERCENT_RANK() return for a partition with a single row?
  • How would you compute PERCENT_RANK() and CUME_DIST() without window functions?
  • You need deciles where tied values always share a decile. How would you build them, given that NTILE(10) can split ties?
  • How does CUME_DIST() relate to PERCENTILE_DISC() ?