题解 | #考试分数(三)#
考试分数(三)
http://www.nowcoder.com/practice/b83f8b0e7e934d95a56c24f047260d91
使用开窗函数解决,在每个分区内进行排名,选择排名小于等于2的
SELECT c.id,c.name,c.score FROM (select g1.id,l1.name,g1.score,DENSE_RANK() over(partition by l1.name order by g1.score DESC) d FROM grade g1 join language l1 on g1.language_id=l1.id ) c WHERE c.d<=2 order by c.name,c.score desc,c.id
但是有一疑问,over()内的order by 似乎只能加一个参数(不太懂)