Mysql
 sql >> Database >  >> RDS >> Mysql

Seleziona n righe casuali per gruppo specificato

Demo di SQLFiddle

select ID,NAME,REPORT_ID
from
(
select *, @row:=if([email protected],@row,0)+1 as rn, @name:=name from 
(select *,RAND() as trand from t) t1,
(select @row:=0,@name:='') tm2 
order by name,trand
) t2
where rn<=10