How can I restart my Row_Number after a certain number of rows.
E.g.
How can I turn
ID RowNumber ------------- 100 1 101 2 102 3 125 4 126 5
Use the modulo operator:
select id, rownumber, 1 + ((rownumber - 1) % 4) from table t;
If rownumber is not a column, you can also use the row_number() function:
rownumber
row_number()
select id, row_number() over (order by id), 1 + ((row_number() over (order by id) - 1) % 4) from table t;