22,181
社区成员




void Done(char *url,int *hit, int cnt)
{
int i, j;
for(i=0;i <cnt; i++)if(hit[i]==1){
j= i==cnt-1? 0:i+1;
printf( url[j] ); hit[j]=1; hit[i]=0;
break;
}
}
select id=row_number() over (order by url),* into #Temp from tb
declare @count int
set @count=1--这是第一次
update #Temp set Hit=1 where @count%3=id
update #Temp set Hit=0 where @count%3<>id
set @count=2
update #Temp set Hit=1 where @count%3=id
update #Temp set Hit=0 where @count%3<>id
...
select id=row_number() over (order by url),* into #Temp from tb
declare @count int
set @count=1--这是第一次
update #Temp set Hit=1 where @count%3=id
update #Temp set Hit=1 where @count%3<>id
set @count=2
update #Temp set Hit=1 where @count%3=id
update #Temp set Hit=1 where @count%3<>id
.........
不管你循环多少次,每次只要传入这个@count就OK了。
select row=row_number() over (order by url),* into # from tb
declare @i int
set @i=1
while (@i<10)
begin
declare @t int
select @t=row from # where hit=1
update #
set hit=0
where row=@t
update #
set hit=1
where row=case when @t=(select max(row) from #) then 1
else @t+1 end
select * from #
set @i=@i+1
end
这里只给你循环了十次