—rank()over(order by 列名 排序)的结果是不连续的,如果有4个人,其中有3个是并列第1名,那么最后的排序结果结果如:1 1 1 4
select scoreid, studentid,COURSENAME,totalexamscore ,
rank()over(order by TOTALEXAMSCORE desc)orderbyNum
from CJ_SCORECOURSE a ,CJ_COURSESCORE b
where a.SCORECOURSEID = b.SCORECOURSEID
—dense_rank()over(order by 列名 排序)的结果是连续的,如果有4个人,其中有3个是并列第1名, 那么最后的排序结果如:1 1 1 2
select scoreid, studentid,COURSENAME,totalexamscore ,
dense_rank()over(order by TOTALEXAMSCORE desc)orderbyNum
from CJ_SCORECOURSE a ,CJ_COURSESCORE b
where a.SCORECOURSEID = b.SCORECOURSEID
SQL排名函数详解
本文深入解析了SQL中的rank()和dense_rank()函数的使用方法及其区别。通过具体案例,展示了当存在并列名次时,两种函数如何生成不同的排序结果。rank()函数在遇到并列名次时会跳过相应的数值,而dense_rank()则不会,确保了名次的连续性。
4458

被折叠的 条评论
为什么被折叠?



