SELECT @i:=@i+1 rowNum,
if(@total=t.s_score,@rank,@rank:=@i) rank,@total:=t.s_score,
t.*
from(
select t1.* ,t2.s_score from student t1 LEFT JOIN score t2 on t1.s_id=t2.s_id and t2.c_id="01" ORDER BY t2.s_score desc
)t,(select @i:=0,@rank:=0,@total:=null) s ;
SELECT @i:=@i+1 rowNum,
if(@total=t.s_score,@rank,@rank:=@rank+1) rank,@total:=t.s_score,
t.*
from(
select t1.* ,t2.s_score from student t1 LEFT JOIN score t2 on t1.s_id=t2.s_id and t2.c_id="01" ORDER BY t2.s_score desc
)t,(select @i:=0,@rank:=0,@total:=null) s ;
select id,maxScore,(@rowNum:=@rowNum+1) as rowNo
from t_user,
(select (@rowNum :=0) ) b
order by t_user.maxScore desc
select u.rowNo from (
select id,(@rowNum:=@rowNum+1) as rowNo
from t_user,
(select (@rowNum :=0) ) b
order by t_user.maxScore desc ) u where u.id="2015091810371700001";
以上所述是小編給大家介紹的Mysql排序獲取排名,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!