RANK() works a lot like ROW_NUMBER() except that it will not break ties, you will not get a unique value for ties.
Select SalesOrderID, CustomerID,
RANK() Over (Order By CustomerID) as RunningCount
From Sales.SalesOrderHeader
Where SalesOrderID>10000
Order By CustomerID
SalesOrderID CustomerID RunningCount
------------ ----------- --------------------
43860 1 1
44501 1 1
45283 1 1
46042 1 1
46976 2 5
47997 2 5
49054 2 5
50216 2 5
51728 2 5
57044 2 5
63198 2 5
69488 2 5
44124 3 13
. . . More
Dense_Rank tomorrow...
Page rendered at Saturday, February 4, 2023 7:42:42 AM (Eastern Standard Time, UTC-05:00)
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.