MYSQL sort within group
group_concat + order by
SELECT id,substring_index(GROUP_CONCAT(id ORDER BY score desc),',',3) as num from
test GROUP BY class
SELECT id,substring_index(GROUP_CONCAT(id ORDER BY score desc),',',3) as num from
test GROUP BY class