Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Wählen Sie n zufällige Zeilen pro angegebener Gruppe aus

SQLFiddle-Demo

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