记得原来用FOXPRO的时候,为了进行排名要专门写一个过程,很复杂,还要考虑并列名次,现在只要一条SQL语句就可以搞定:
        /*排名语句

         ---全县排名
         select 姓名,总分, (select count(*)+1 from 成绩 where a.总分>成绩.总分) as 名次 from 成绩 a


         ---分校排名
         select 校名,姓名,总分, (select count(*)+1 from 成绩 where 成绩.总分>a.总分 and 成绩.校名=a.校名) as 名次 from 成绩 a where 校名='XXXX学校' order by 校名,名次

         ---几个学校组合排名
         select 校名,姓名,总分, (select count(*)+1 from 成绩 where 成绩.总分>a.总分) as 名次 from 成绩 a where 校名 in ('XX1学校','XX2学校')  order by 名次
*/


        

相关文章: