你要几条记录?? 你可以写成存储过程: 如要20条: create procedure 名 as begin select * into #temp from tkt where 1=2 while (select count(*) from tkt)<20 begin insert #temp select top 19 * from tkt order by newid() insert #temp select top 1 tkt from tkt where 编号 not in (select 编号 from #temp) and tx=(30-(select sum(tx) from #temp)) order by newid() end end
你可以写成存储过程:
如要20条:
create procedure 名
as
begin
select * into #temp from tkt where 1=2
while (select count(*) from tkt)<20
begin
insert #temp select top 19 * from tkt order by newid()
insert #temp select top 1 tkt from tkt where 编号 not in (select 编号 from #temp) and tx=(30-(select sum(tx) from #temp)) order by newid()
end
end