日期:2014-05-16  浏览次数:20787 次

mysql分组排序并获得排序号码

数据表 grades:


需要得到查询结果:

sql语句:


?select *, (select count(1) + 1 ?from grades B ?where A.gender = B.gender and A.grade < B.grade) as rank from grades A order by gender , grade desc;
?
?参见:

http://topic.csdn.net/u/20110411/10/a303ad9d-d061-4781-952f-7de9897f0bed.html