sql如何进行分层随机抽样

来源:百度知道 编辑:UC知道 时间:2024/06/10 07:53:29
例如:
表一
A B C
大 1 9
大 5 6
大 4 7
小 8 6
小 3 2
中 3 2
中 5 1
中 1 7
中 7 2
我想对列A进行按百分比分类随机抽样,也就是说同时从列A的“大”中抽取60%,从列A的“小”中抽取60%,从列A的“中”中抽取60%。在SQL Server 2000中如何进行,望各位大大帮帮忙!!

--按大、中、小 分别选取 然后再组合
--按新字段重新排序后,你选出来的就是随机的了
select top 60 percent * from table_1 where A='大' order by B
union all
select top 60 percent * from table_1 where A='中' order by B
union all
select top 60 percent * from table_1 where A='小' order by B

select top 60 percent * from table where a='大' order by newid()
union all
select top 60 percent * from table where a='中' order by newid()
union all
select top 60 percent * from table where a='小' order by newid()