I have data in my table as below
Now I want to generate unique rank value to each duplicate value like 1,2,3,4 etc as below
How to do this in SQL Server 2016?
Advertisement
Answer
You seem to be looking for row_number()
:
select t.*, row_number() over (partition by id, name order by deptid) as ranking from t;