22,209
社区成员
发帖
与我相关
我的任务
分享
declare @t table(id int)
declare @num int, @id int, @fc int
set @num = 5
while @num>0
begin
select top 1 @id=ID, @fc=FillCount from tbname where FillCount<=@num and ID not in (select id from @t) order by newid()
insert @t select @id
set @num = @num - @fc
end
select * from @t
declare @t table(id int)
declare @num int, @id int, @fc int
set @num = 5
while @num>0
begin
select top 1 @id=ID, @fc=FillCount from tbname where colid<=@num and ID not in (select id from @t) order by newid()
insert @t select @id
set @num = @num - @fc
end
select * from @t