row_number() Group by? row_number() Group by? sql-server sql-server

row_number() Group by?


Here is alternate solution.

You need not worry about the ordering of Cat. Using following SQL you will be able to get unique values for your Date & Cat combination.

SELECT    Date,       ROW_NUMBER() OVER (PARTITION BY Date, Cat ORDER By Date, Cat) as ROW,   Cat,   QtyFROM SOURCE


DENSE_RANK() OVER (PARTITION BY date ORDER BY cat)