SQL面试50题-25
25、查询各科成绩前三名的记录(不考虑成绩并列情况)(重点 与22题类似
SELECT * FROM (SELECT s_id,c_id,ROW_NUMBER() OVER(PARTITION BY c_id ORDER BY s_score) ranking FROM Score) m INNER JOIN Student s ON s.s_id = m.s_id WHERE m.ranking IN (1,2,3) ORDER BY m.c_id,m.ranking