Skip to content
Advertisement

Row_Number Sybase SQL Anywhere change on multiple condition

I have a selection that returns

And i want to add a row number (il’l use it as a primary id) but i want it to change always when the “EMP” changes, and also won’t change when the doc is same as previous one like:

In SQL Server I could use LAG to compare previous DOC but I can’t seem to find a way into SYBASE SQL Anywhere, I’m using ROW_NUMBER to partitions by the “EMP”, but it’s not what I need.

Anyone have a direction for this?

Advertisement

Answer

You sem to want dense_rank():

This numbers rows within groups having the same emp, and increments only when date changes, without gaps.

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