Solve “Deduplicate events with ROW_NUMBER”

Free. Runs in your browser, no install.

SQL · Window Functions

What is NTILE()?

Mediumntilebucketingsegmentation

Interview question

What is NTILE()?

How to answer

The short answer

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

For quartiles:

SQL
NTILE(4) OVER (
    ORDER BY total_spend
)

Customers are assigned:

Useful for:

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

Lock it in with a real drill

You remember an answer longer once you have used it. Try a hands-on problem on this concept.

Open related drill