Skip to content
Advertisement

How to replace identical values with incremental integers?

I have this SQL select:

The output will look something like this:

How can I replace the identical values of UserId with incremental integers, so that the output will look something like this:

I have tried grouping the identical UserId rows first then joining it with the same table while having an incremental int declared but no success there. It seems like there must be an easier way to do this?

Advertisement

Answer

You could use DENSE_RANK:

screen capture from demo link below

Demo

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