Skip to content
Advertisement

How to count/increment the current number of occurances of a table column in a MS SQL select

I have a table which looks like this:

and I want to add another column with a number which increments everytime row name occurs, e.g.:

I’m not really sure how to achieve this. Using count() I will only get the total number of occurances of name but I want to increment n so that I have a distinct value for each row.

Advertisement

Answer

You want row_number() :

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