题解 | #考试分数(三)#
考试分数(三)
http://www.nowcoder.com/practice/b83f8b0e7e934d95a56c24f047260d91
- grade_rank 查询每个项目的分组排名
- top_2 中查询各个项目前二的人
- 然后就是匹配了
with grade_rank as (
select id,language_id,score,
dense_rank()over(partition by language_id order by score desc) sc_rank
from grade ),
top_2 as (
select id,language_id,score,sc_rank from grade_rank where
sc_rank <=2)
select a.id,name,score from top_2 a left join
language b on a.language_id == b.id
order by name,score desc