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