# 36.查询每门成绩最好的前两名
with linshi as(
select * ,
rank() over(partition by CId order by score desc) as 'rank_score'
from SC)
select *
from linshi
where rank_score<=2;
分析:
1.利用排名函数可以将成绩表中按学科分组后,按成绩排序,再排名,
2.利用with用法存入临时表
3.然后取前两名,就不用担心重复的情况了,。。。。