select * from (
select *,
@group_index := CASE WHEN @prev_group = province THEN @group_index + 1 ELSE 1 END AS group_index,
@prev_group := province
from (
select * from sb_node order by province,rand()
) AS T1
) as T2 where group_index <=[n]
参考: http://stackoverflow.com/questions/2643314/mysql-group-by-limit
@用来声明变量,order by province之后数据相当于根据province分组了,然后给数据增加一个分组内的序号group_index,之后想取几个根据group_index查就ok啦
我···看不懂语法,这@是干嘛的···还有:=