mysql 查询排行榜, 查询用户第几名
Posted supramolecular
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql 查询排行榜, 查询用户第几名相关的知识,希望对你有一定的参考价值。
查询排行榜
SELECT t.*, @rank_num := @rank_num + 1 AS rank_num FROM (SELECT @rank_num := 0) r, (SELECT nickname, type, wx_nickname, wx_avatar, share_viewers_count FROM `live_audiences` where video_id = 7 ORDER BY share_viewers_count DESC LIMIT 20) as t
查询用户第几名
SELECT b.* FROM (SELECT t.*, @rank_num := @rank_num + 1 AS rank_num FROM (SELECT @rank_num := 0) r, (SELECT id, nickname, type, wx_nickname, wx_avatar, share_viewers_count FROM `live_audiences` where video_id = 7 ORDER BY share_viewers_count DESC ) as t) AS b where id = 8
以上是关于mysql 查询排行榜, 查询用户第几名的主要内容,如果未能解决你的问题,请参考以下文章
mysql 查询记录 排序之后 查看指定记录 在数据库中位于第几行