小白麻烦各位了 谢谢 -.-! 顶者有分

zjybushiren88888 2009-04-13 03:38:02
字段 Url Hit
AAA 0
BBB 0
CCC 1

循环显示记录AAA,BBB,CCC
当HIT 为 1的时候 则显示AAA 同时把AAA的HIT设置为1 CCC的HIT设置为0
则下次显示的数据为BBB 同时把BBB的HIT设置为1 AAA的HIT设置为0

请问各位高手 这种如何实现 提供伪代码最好 顶者有分
...全文
437 33 打赏 收藏 转发到动态 举报
写回复
用AI写文章
33 条回复
切换为时间正序
请发表友善的回复…
发表回复
xempo 2009-04-22
  • 打赏
  • 举报
回复

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;
}
}

读书不为功名,闲来也作小诗。
TSNOKIA 2009-04-17
  • 打赏
  • 举报
回复
不错
goeasy2005 2009-04-16
  • 打赏
  • 举报
回复
顶了
vip__888 2009-04-16
  • 打赏
  • 举报
回复
帮顶了
zlalalal 2009-04-15
  • 打赏
  • 举报
回复
顶了
taoistong 2009-04-15
  • 打赏
  • 举报
回复
怎么还不结
taoistong 2009-04-15
  • 打赏
  • 举报
回复
19的#应该变成##,否则表就没了
xempo 2009-04-15
  • 打赏
  • 举报
回复

for(i=0;i<3;i++){
if(hit[i]==1){
switch(i){
case 0 : printf( url[1] ); hit[1]=1; hit[0]=0;
break;
case 1 : printf( url[2] ); hit[2]=1; hit[1]=0;
break;
case 2 : printf( url[0] ); hit[0]=1; hit[2]=0;
break;
}
}
我是告诉你方法,剩下的你自己调试,我要去睡觉了。
xne2ds 2009-04-15
  • 打赏
  • 举报
回复

阿良 2009-04-14
  • 打赏
  • 举报
回复
19楼正解!
wangbin1986 2009-04-14
  • 打赏
  • 举报
回复
18楼很有创意啊!
热学沸腾56 2009-04-13
  • 打赏
  • 举报
回复
up,接分!
ai_li7758521 2009-04-13
  • 打赏
  • 举报
回复
jinglong6511 2009-04-13
  • 打赏
  • 举报
回复
up
Zoezs 2009-04-13
  • 打赏
  • 举报
回复
有点错。

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
...
Zoezs 2009-04-13
  • 打赏
  • 举报
回复
我有办法了,你做个计数的变量,每变一次count=count+1

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

这里只给你循环了十次
xiequan2 2009-04-13
  • 打赏
  • 举报
回复
up
ks_reny 2009-04-13
  • 打赏
  • 举报
回复
[Quote=引用楼主 zjybushiren88888 的帖子:]
字段 Url Hit
AAA 0
BBB 0
CCC 1

循环显示记录AAA,BBB,CCC
当HIT 为 1的时候 则显示AAA 同时把AAA的HIT设置为1 CCC的HIT设置为0
则下次显示的数据为BBB 同时把BBB的HIT设置为1 AAA的HIT设置为0

请问各位高手 这种如何实现 提供伪代码最好 顶者有分
[/Quote]
楼主能不能给点数据呀。
milk111 2009-04-13
  • 打赏
  • 举报
回复
up
加载更多回复(13)

22,181

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧