select *,num=(select count(1) from table1 a where a.id<=table1.id) from table1

解决方案 »

  1.   

    select 
        a.*,
        (select count(*) from 表 where col2=a.col2 and col3=a.col3 and ID<=a.ID)
    from
        表 a
      

  2.   

    select *,aid =identity(int,1,1) into # from tablename
    select *,(select count(*)+1 from # where id<a.id and col1=a.col1 and col2=a.col2 and col3=a.col3)
    from #
    drop table #
      

  3.   

    --写的是id也一样的情况下的。
    select *,aid =identity(int,1,1) into # from tablename
    select *,(select count(*)+1 from # where aid<a.aid and col1=a.col1 and col2=a.col2 and col3=a.col3)
    from #
    drop table #