Skip to content
Advertisement

How can I increment counter when the value in another column changes without sorting the column?

I have the following table I have the following table

And I need to be able to increment the counter value when the Name changes in SQL

And I need to be able to increment the counter value when the Name changes in SQL

Advertisement

Answer

You need a column that specifies the ordering of the columns — because SQL tables represent unordered sets. If you have one, you can do use a gap-and-islands trick with the difference of row numbers:

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