我从多个表中选出了一系列的数据,建成一个排名表,排出前n位。生成的报表中有一栏名次,当然是从1~n了。由于一定要用绑定(一定要用),该列须自动生成。可是该列怎么生成啊?偶想了很多办法也办不到。平台为VB6.0+SQL Sever2000。还请各位大虾帮忙。

解决方案 »

  1.   

    select IDENTITY(int, 1,1) ,id,name,piont into newtalbename from yourtable order by pion
      

  2.   

    建存储过程,类似这样处理:select *,identity(int,1,1) as rank into #t from 表 order by 排名字段 desc
    select * from #t
    drop table #t
      

  3.   

    简单点,不考虑并列。如何使用存储过程?我没用过啊。
    我想用chewinggum(口香糖·目标两颗星星) 的方法,程序中添加一列来处理,但由于从多个数据表中生成的,无法修改。
      

  4.   

    select *,identity(int,1,1) as rank into #t from 表 order by 排名字段 desc
    select * from #t
    无法得到正确的顺序,会出现2,1,3这样的情况
      

  5.   

    好像是先写入#t,然后才对其排序。rank字段是生成的是1~n的数,但是就是没排序好。
      

  6.   

    假设你的纪录集为“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
      

  7.   

    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
      

  8.   

    我想用chewinggum(口香糖·目标两颗星星) 的方法,程序中添加一列来处理,但由于从多个数据表中生成的,无法修改。
    __________________________________________________
    我的意思是处理你最终获得的那个数据集。
    你已经从多个数据表中生成数据了,那么你的程序中应该已经有一个recordset来接受这个数据集了吧。先调用一次recordset的open方法,然后recordset.Fields.Append 增加一列。接下来就可以循环往这列里面写入序号。循环过程中稍微做一点控制就能够解决并列排名问题了
      

  9.   

    假设你的纪录集为“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