达梦 :1. 自动生成序号
select rownum as '序号',id,name from student
mysql:
SELECT (@i:=@i+1) as '序号', id from student,(select @i :=0) b
2. 某个字段的排名生成序号(mysql 需要8.0以上版本)
rank():是并列排序,会跳过重复序号。
dense_rank():是并列排序,不会跳过重复序号。
row_number():是顺序排序,不跳过任何一个序号,就是行号
用法:dense_rank() over (order by score desc),
-- 并列排序,不会跳过重复序号select s.age, dense_rank() over(order by s.age desc) as '序号' from student s--并列排序,跳过重复序号select s.age, rank() over(order by s.age desc) as '序号' from student s--顺序排序,不跳过重复序号select s.age, row_number() over(order by s.age desc) as '序号' from student s
来源地址:https://blog.csdn.net/job_csdn/article/details/127927310