with tt as
(select sc.CId ,sc.SId, sc.score,
ROW_NUMBER ( ) OVER ( PARTITION BY sc.cid ORDER BY sc.score DESC ) AS rank2
from sc )
select tt.*, s.sname from tt join student s on tt.sid=s.sid
where tt.rank2 <3
ORDER BY tt.cid
####PARTITION BY sc.cid ORDER BY sc.score DESC 根据sc.cid分区后根据score排序。
with as 算一个单独写的函数,单独写出来可单独调用