Increment value on column every N records on table
问题 I need to increment +1 every 4 records over a table column, I've tried to use ROW_NUM() but my dirty workaround does not make sense. This is what I need: Index PeriodID 1 1 1 2 1 3 1 4 2 5 2 6 2 7 2 8 PeriodID is the primary key (clustered index) for table "Periods", I've heard about window functions LAG() and LEAD() but not sure if I can apply the concept for this scenario, the following syntax is my failed dirty trick attempt: select row_number() over (order by periodid)/4+1, periodid from