Not 25% of successive results like here, but 25% of the base table so that it's split evenly in four (assigning to a fourth). How to? There must be some simpler solution that I'm missing.DECLARE @quartile TABLE (CustomerID INT NOT NULL UNIQUE,Quartile INT NOT NULL);DECLARE @i TINYINT = 1;WHILE @i < 5BEGININSERT @quartile ( CustomerID, Quartile )SELECT DISTINCT TOP 25 PERCENT T.CustomerID, [Quartile] = @iFROM #Temp AS TWHERE NOT EXISTS (SELECT 1FROM @quartile qWHERE q.CustomerID = T.CustomerID);SET @i = @i + 1END ;SELECT Quartile, COUNT(CustomerID)FROM @quartileGROUP BY Quartile