SQL面试50题-19

题目链接:https://zhuanlan.zhihu.com/p/43289968

按各科成绩进行排序,并显示排名(重点row_number)
知识点:row_number()、rank()、dense_rank()

1.对课程进行分组的情况
SELECT s_id,c_id,s_score,
ROW_NUMBER() OVER (*PARTITION BY c_id *ORDER BY s_score DESC) AS ranking
FROM score

2.不对课程分组的情况
SELECT s_id,c_id,s_score,
ROW_NUMBER() OVER (ORDER BY s_score DESC) AS ranking
FROM score

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务