时间:2021-07-01 10:21:17 帮助过:3人阅读
SQL查询记录中增加序列号
根据学生成绩在查询结果中增加排名字段:
1.SELECT ROW_NUMBER() OVER (ORDER BY SCORE ASC) AS RANK,NAME,SCORE FROM GRADE ORDER BY SCORE;
此写法是直接在结果记录添加顺序排序序号
2.SELECT RANK() OVER (ORDER BY SCORE ASC) AS RANK,NAME,SCORE FROM GRADE ORDER BY SCORE;
此写法的根据排序依据列的值进行连续的顺序排序,但遇到值相同则序号相同;
3.SELECT DENSE_RANK() OVER (ORDER BY SCORE ASC) AS RANK,NAME,SCORE FROM GRADE ORDER BY SCORE;
此写法的根据排序依据列的值进行不连续的顺序排序,遇到值相同则序号相同,但之后的序号会自动加2,不连续;
SQL查询结果增加序列号
标签: