随机从某个表中取150条数据,其中表中的id随你的表的记录数而定,我现在测试用的是10000
create table #t( id int,name varchar(50))
declare @random_Id int
declare @Count int
declare @temp int
set @Count=1
while @Count<=150
begin
select @random_Id=cast(10000*rand() as int)
if (@random_Id!=0)
set @temp=(select top 1 id from person_main where id =@random_Id and person.id not in (select id from #t))
if(@temp is not null)
begin
insert into #t
select top 1 id,name from person_main where id =@random_Id and person.id not in (select id from #t)
set @Count=@Count+1
end
end
select * from #t
drop table #t