sql按照查询排名加上排名的名次字段

格式

SELECT (@rowNO := @rowNo+1) AS rowno FROM (

SELECT * FROM (自己的表名)

) a,(SELECT @rowNO :=0) b

例子:根据分数排名并且加上排名名次字段rowno

SELECT (@rank := @rank+1) AS rank,a.name,a.score FROM (

SELECT s.name,s.score FROM student s order by s.score

) a,(SELECT @rank :=0) b

发表评论

邮箱地址不会被公开。 必填项已用*标注