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)