Turn NTILE output into a simple segment label.
Section: Segmentation patterns
Flag top quartile customers
sql
sql
WITH bucketed AS (
SELECT customer_id,
lifetime_value,
NTILE(4) OVER (ORDER BY lifetime_value DESC) AS quartile
FROM customers
)
SELECT customer_id,
lifetime_value,
CASE WHEN quartile = 1 THEN 'top_quartile' ELSE 'other' END AS segment
FROM bucketed;Explanation
This is a simple but effective pattern for growth, CRM, and pricing analysis.
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 Segmentation patterns
Build labeled score bands
Assign named score ranges using a window bucket.
Find the 90th-percentile style cutoff
Identify rows at or above a cumulative threshold.