NTILE divides ordered rows into a specified number of approximately equal groups.
It is useful for segmentation such as top 25%, middle 50%, and bottom 25%.
Divide customers into four sales-performance groups.
SELECT
c.CustomerName,
SUM(o.OrderAmount) AS TotalSales,
NTILE(4) OVER (
ORDER BY SUM(o.OrderAmount) DESC
) AS SalesQuartile
FROM Customers c
LEFT JOIN Orders o
ON c.CustomerID = o.CustomerID
GROUP BY c.CustomerName;
Used in customer segmentation, performance analysis, marketing, and risk classification.
- NTILE divides rows into numbered groups.
- ORDER BY determines group assignment.
- NTILE(4) creates four groups.
- Groups may not contain exactly equal numbers of rows.
- Useful for percentile-style segmentation.
What does NTILE(4) do?
It divides the ordered result into four approximately equal groups.
Where is NTILE useful?
It is useful for customer segmentation, performance quartiles, and ranking-based analysis.