Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing
Back
  1. Home
  2. Interview prep
  3. What is NTILE()?

SQL · Window Functions

What is NTILE()?

Mediumsql-23
ntilebucketingsegmentation

Question

What is NTILE()?

Solution

NTILE(n) divides ordered rows into approximately equal buckets.

For quartiles:

NTILE(4) OVER (
    ORDER BY total_spend
)

Customers are assigned:

1 → lowest 25%
2 → next 25%
3 → next 25%
4 → highest 25%

Useful for:

  • Customer segmentation
  • Revenue analysis
  • Salary bands
  • Top/bottom groups

🎯 Put this concept into practice

Solidify this answer with real hands-on interview drills in the browser studio.

Open related drill →
PreviousNext