求高手指点!随机抽样问题!(急)
我有一张表mytable!比如里面只有3个字段,
mobile,province,city 都是char型
我现在要想随机查询表里的内容!
(mobile为手机号-前7个字符为手机的号段(比如13656565656 1365656为号段),共有80个号段,province为省份-已知有31个省)
条件:随机抽40个号段,10个省份,每个号段750个记录 共300000个记录!
请高手指点一下了!谢谢!
[解决办法]
select * from (select *
row_number() over(order by mobile) as rownum,
rank() over(order by mobile) as rnk,
dense_rank() over(order by mobile) as densernk
from mytable where province in (
select top 10 distinct province,newid() as id from mytable order by id)
and mobile in
(select top 40 distinct mobile ,newid() as id from mytable order by id )
order by mobile ,province)
Where rnk <=750
你说MOBILE按前7位算,那看你的表结构中是如何存的了,如果分开存,你改一下字段就行了,否则你就用SUBSTRING函数就可以了。