SQL用row_number进行循环查询

declare @count int=0,@R int=0
select row_number()over(order by RoomID) as R,* into #t from Room where RMClassID='2'
select @count=COUNT(0) from #t
while(@R<@count)
begin
   set  @R=@R+1
   insert into RM select * from #t where R=@R
end
drop table #t

05-11 13:42