select identity(int,1,1) as xh,* into #a from TB 
ORDER BY studentid
select * from #a

解决方案 »

  1.   

    如果studentid连续的话
    select (select count(*) from score where studentid<a.studentid) as xh,studentid,score from score a
      

  2.   

    select (select count(*) from score where studentid<=a.studentid) as xh,studentid,score from score a oder by xh
      

  3.   

    我也来一个:
       select xh=identity(int,1,1),* into #a from TB 
       select * from #a
       drop table #a
      

  4.   

    select identity(int,1,1) as xh,* into #a from TB 
    ORDER BY studentid
    select * from #a该方法只能适用于无IDENTITY关键字表
    select (select count(*) from score where studentid<=a.studentid) as xh,studentid,score from score a oder by xh序号从0开始排