【笔记】MySQL查询排名

select a.name, a.total_score,@rank:=@rank+1 as rank from (    
              select u.name,uti.total_score from user_total_integral uti left join tuser u on uti.user_id=u.id  WHERE u.status = 1 AND u.id <> '9001' and total_score>0 GROUP BY  uti.user_id  ORDER BY uti.total_score  DESC ,uti.user_id DESC
        ) a ,(select @rank:=0) b

原文地址:https://www.cnblogs.com/mybug/p/6151761.html