RANK, DENSE_RANK, ROW_NUMBER
语法
<窗口函数> OVER ([PARTITION BY <列清单>] ORDER BY <排序用列清单>)
SELECT student_name, score, DENSE_RANK() OVER(ORDER BY score DESC) AS 'rank' FROM grade;
SELECT student_name, score, ROW_NUMBER() OVER(PARTITION BY course_name ORDER BY score DESC) AS 'rank' FROM grade;
1.直接排序:按照某列对数据进行排序
2.Top-k:查询排名TOP-k的数据
3.最值问题:查询最大、最多的数据
4.辅助列:比如计算连续登陆问题、用SQL计算平均数、众数、中位数(可以参考我之前的视频)