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

Seleziona fino a x righe di ciascun gruppo

SELECT  id, name, job, rank
FROM    TableName a
WHERE 
        (
           SELECT   COUNT(*) 
           FROM     TableName as f
           WHERE    f.job = a.job AND 
                    f.rank <= a.rank
        ) <= 2;