个人名次
select a.uid,a.total,if(b.uid is null,1,count(*)+1) as grade from (select uid,sum(mark) as total from tb where uid=4 group by uid) as a left join (select uid,sum(mark) as total from tb group by uid) as b on a.total<b.total group by uid
成绩列表
select a.uid,a.total,if(b.uid is null,1,count(*)+1) as grade from (select uid,sum(mark) as total from tb group by uid) as a left join (select uid,sum(mark) as total from tb group by uid) as b on a.total<b.total group by uid order by grade