SQL Window Functions: Percentiles, Bucketing, and Distribution Analysis/Create deciles with NTILE(10)
Bucket rows into 10 groups.
Section: Distribution functions
Create deciles with NTILE(10)
sql
sql
SELECT customer_id,
spend,
NTILE(10) OVER (ORDER BY spend DESC) AS spend_decile
FROM customers;Explanation
Great for segmentation, scoring, and rough percentile groupings.
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 Distribution functions