题解 | 考试分数(三)
SELECT id, `name`, score FROM ( SELECT g.id, `name`, score, DENSE_RANK() over ( PARTITION BY `name` ORDER BY score DESC ) AS ranking FROM grade AS g, `language` AS l WHERE g.language_id = l.id ) AS t WHERE t.ranking = 1 OR t.ranking = 2 ORDER BY `name` ASC, score DESC, t.id ASC