Talvin Singh - Sunday, February 4, 2018 12:15 PM
No problem.
Shifting gears a bit, you'll get faster and better answers in the future if you provide your data in a readily consumable format, like this....
SELECT *
INTO #TestTable
FROM (VALUES
('Order1', 4)
,('Order2',12)
,('Order3',12)
,('Order4',12)
,('Order5',29)
,('Order6',31)
,('Order7',49)
)v(OrderID,Point)
;
Try this with that data. I threw in one of the obvious extra columns that I thought you might also be looking for.
SELECT OrderID
,Point
,GroupCode = DENSE_RANK()OVER (ORDER BY Point)
,OrdersInGroup = COUNT(*) OVER (PARTITION BY Point)
FROM #TestTable
ORDER BY GroupCode, OrderID
;
Here are the results.
--Jeff Moden
Change is inevitable... Change for the better is not.