Skip to content
Advertisement

How to give row number for consecutive combination and duplicate it for duplicates

I created simple table to illustrate my problem:

So I want to give row number to each row but repeat it when Type and SectionId is the same:

if I try ROW_NUMBER() Over (Partition by SectionId, Type Order by id) I will get result like that:

Please tell me if there are any way to do that.

Database that I used is Microsoft SQL Server (ver. 14.00.3045)

Advertisement

Answer

Use dense_rank() instead of row_number():

db<>fiddle

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement