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

请教怎么插入排序结果?
请教一个问题:我想对1万学生的成绩进行排序,并把名次写入一个字段,怎么做效率最高!
如果有两个成绩相同则都是第一名,而下一个应该为第三名.
表结构:chengji为成绩,paixu为排序结果
id       chengji     paixu
001     99                   1
002     99                   1
003     98                   3
004     98                   3
005     97                   5
请使用SQL语言来实现,我是要用到ASP中.谢谢了!

------解决方案--------------------
SELECT *,(select count(*) from ttp where a.chengji <chengji)+1 from ttp a

------解决方案--------------------
--用子查询即可

SELECT *,(select count(*) from 表名 where a.chengji <chengji)+1 as paixu from 表名 a

------解决方案--------------------

--用子查询即可

SELECT *,(select count(*) from 表名 where a.chengji <chengji)+1 as paixu from 表名 a

--或

SELECT *,(select count(*) from 表名 where a.chengji <=chengji) as paixu from 表名 a
------解决方案--------------------
--如果更新,需要用到域函数Dcount()

update 表名 a set paixu=dcount( "ID ", "表名 ", "chengji> = " & a.chengji)

--或

update 表名 a set paixu=dcount( "ID ", "表名 ", "chengji> " & a.chengji)+1