Skip to content
Advertisement

Set row number for batch of N rows per category

I have table

I want to create a another column in which i have to put row number.

Logic : For 3 rows, it should be same and change to next value for 4th row. And Whenever the PHASE is changing, it should go to next number even if the set of 3 is not complete for the previous number.

Expected Output

I have tried the below query, but it is not giving me the required output.

Actual Output:

I have tried with DENSE_RANK() as well but not getting the expected output.

FIDDLE HERE

Advertisement

Answer

Give it a try:

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