Generate Row Number for every 3 rows
问题 I want generate number for every three rows CREATE TABLE #test(period INT) INSERT INTO #test VALUES (602),(603),(604),(605),(606),(607),(608),(609) I know we can generate sequence using row_number window function or while loop or cursor SELECT period, ( Row_number()OVER(ORDER BY period) - 1 ) / 3 + 1 FROM #test Result; +--------+-----+ | period | seq | +--------+-----+ | 602 | 1 | | 603 | 1 | | 604 | 1 | | 605 | 2 | | 606 | 2 | | 607 | 2 | | 608 | 3 | | 609 | 3 | +--------+-----+ Is there any