sql随机取一条数据 sql如何进行分层随机抽样?

sql如何进行分层随机抽样?--按大、中、小 分别选取 然后再组合--按新字段重新排序后,你选出来的就是随机的了select top 60 percent * from table_1 where A

sql如何进行分层随机抽样?

--按大、中、小 分别选取 然后再组合

--按新字段重新排序后,你选出来的就是随机的了

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

mysql分组后每组随机取一条记录求sql语句?

使用orderbynewid()随即排序然后用top1/3客户数量取A的客户

然后在剩下2/3的记录中再用newid()随机排序然后取1/2的客户给B

剩下的为C的客户