table userinfo(userid,username,cityid,mobile)
现在要一个sql来随机抽取用户信息,要求每个cityid取5条记录,这个怎么写啊
------解决方案--------------------------------------------------------
按顺序则可以参考下贴中的几种方法。
http://topic.csdn.net/u/20091231/16/5c5fd526-b2bc-42bf-9a20-92b82b1e9452
分组取最大N条记录方法征集
------解决方案--------------------------------------------------------
select * from (
select *,ROW_NUMBER() over(partition by cityid order by px) as n1 from (
select *,rand() as px from tt ) a ) a1 where n1<=5
试试