我要在几百人中随机抽取几个人,保证在一年内每人都抽到,但又要保证已经抽到的人在规定时间内不出现。请高手给个算法,高分感谢!!!!!!
例:
create table 你的表 (编号 int,姓名 varchar(100))
go
create table 已抽过的用户表 (第几次抽中的 int,编号 int,姓名 varchar(100))
go
insert 已抽过的用户表 select top 10 1,* from 表 where 编号 not in (select 编号 from 已抽过的用户表) order by newid()
上面的1可以你每次执行可以取
select isnull(max(第几次抽中的),0)+1 from 已抽过的用户表
就可以了!
select top M * into #temp from table where 标记=0 order by newid()
update table set 标记=1 where table.名字 in (select 名字 from #temp) --更新这次抽出的人,使其下次不会再被抽出。
select * from #temp ---这次需要的数据