select *,identity(int,1,1) as rank into #t from 表 order by 排名字段 desc select * from #t 无法得到正确的顺序,会出现2,1,3这样的情况
好像是先写入#t,然后才对其排序。rank字段是生成的是1~n的数,但是就是没排序好。
假设你的纪录集为“select top 10 * from ... as AAA or der bai Key”那么有一种方法可以排名:select NUM=1+(select count(Key) from (select top 10 * from ... order by Key) as BBB where BBB.key<AAA.key) ,* from (select top 10 * from ... order by Key) as AAA
select *,identity(int,1,1) as rank into #t from 表 order by 排名字段 desc select * from #t 无法得到正确的顺序,会出现2,1,3这样的情况 ============================================================================改一下: select identity(int,1,1) as rank, * into #t from 表 order by 排名字段 desc select * from #t drop table #t
假设你的纪录集为“select top 10 * from ... as AAA or der bai Key”那么有一种方法可以排名:select NUM=1+(select count(Key) from (select top 10 * from ... order by Key) as BBB where BBB.key<AAA.key) ,* from (select top 10 * from ... order by Key) as AAA
select * from #t
drop table #t
我想用chewinggum(口香糖·目标两颗星星) 的方法,程序中添加一列来处理,但由于从多个数据表中生成的,无法修改。
select * from #t
无法得到正确的顺序,会出现2,1,3这样的情况
NUM=1+(select count(Key) from
(select top 10 * from ... order by Key) as BBB where BBB.key<AAA.key)
,*
from (select top 10 * from ... order by Key) as AAA
select * from #t
无法得到正确的顺序,会出现2,1,3这样的情况
============================================================================改一下:
select identity(int,1,1) as rank, * into #t from 表 order by 排名字段 desc
select * from #t
drop table #t
__________________________________________________
我的意思是处理你最终获得的那个数据集。
你已经从多个数据表中生成数据了,那么你的程序中应该已经有一个recordset来接受这个数据集了吧。先调用一次recordset的open方法,然后recordset.Fields.Append 增加一列。接下来就可以循环往这列里面写入序号。循环过程中稍微做一点控制就能够解决并列排名问题了
NUM=1+(select count(Key) from
(select top 10 * from ... order by Key) as BBB where BBB.key<AAA.key)
,*
from (select top 10 * from ... order by Key) as AAA