有一成绩管理系统,按总分给学生成绩排名,在SQL中如何实现
排名情况有:
1。允许并列名次,
2。增删时能相应更改!
---------------------------------------------------------------
select (select count(*)+1 from table1 where 总分 > A.总分 ) as 名次 , *
from table1 as A order by 名次
---------------------------------------------------------------
select (select count()+1 from t where 分数>=A.分数) as '名次', from t A
order by 分数 desc