## 查询所有排名信息
SELECT
p.paperid, p.memberid, p.score, @rownum := @rownum + 1 AS rownum FROM ( SELECT @rownum := 0 ) r, ( SELECT * FROM aaa(表名) WHERE paperid = 82 ORDER BY score DESC ) AS p
这段sql的意思是查询aaa表,条件是paperid =82 按照score DESC 排序,其中paperid、memberid、score是aaa表的字段
1.SELECT @rownum := 0:表示对rownum赋初始值0
2.@rownum := @rownum + 1:表示对rownum加1,语句中会从1开始,每一行往下都自动加1
##查询当前用户排名信息
SELECT
b.paperid, b.memberid, b.score, b.rownum FROM ( SELECT t.*,@rownum := @rownum + 1 AS rownum FROM ( SELECT @rownum := 0 ) r, ( SELECT * FROM aaa(表名)WHERE paperid = 82 ORDER BY `score` DESC ) AS t ) AS b WHERE b.memberid = 127
这段sql的意思是查询aaa表 ,条件是paperid = 82按照score desc排序,取出memberid = 127的用户排名信息,其中paperid、memberid、score是aaa表的字段,rownum 是排名名次
感谢博主,喝杯咖啡~
还没有人发表评论