Divide ordered rows into a fixed number of groups.
Section: Buckets and Percentiles
Bucket rows with NTILE
sql
sql
SELECT customer_id, total_spent,
NTILE(4) OVER (ORDER BY total_spent DESC) AS quartile
FROM customer_lifetime_value;Explanation
NTILE is helpful for quartiles, deciles, and score bands.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Buckets and Percentiles