declare @t table ( c char(1)) insert into @t select 'a' union all select 'b' union all select 'c' union all select 'd' union all select 'e' union all select 'f' union all select 'g' union all select 'h' union all select 'i' union all select 'j' select case when r%5 = 0 then 5 else r%5 end as Xh,* from ( select row_number()over(order by getdate()) as R, * from @t ) t/* (10 行受影响) Xh R c -------------------- -------------------- ---- 1 1 a 2 2 b 3 3 c 4 4 d 5 5 e 1 6 f 2 7 g 3 8 h 4 9 i 5 10 j(10 行受影响) */
declare @t table ( c char(1))
insert into @t
select 'a' union all
select 'b' union all
select 'c' union all
select 'd' union all
select 'e' union all
select 'f' union all
select 'g' union all
select 'h' union all
select 'i' union all
select 'j' select case when r%5 = 0 then 5 else r%5 end as Xh,* from (
select row_number()over(order by getdate()) as R, * from @t
) t/*
(10 行受影响)
Xh R c
-------------------- -------------------- ----
1 1 a
2 2 b
3 3 c
4 4 d
5 5 e
1 6 f
2 7 g
3 8 h
4 9 i
5 10 j(10 行受影响)
*/