select identity(int, 1, 1) as id, name into #test from testselect * from #testdrop table #test

解决方案 »

  1.   

    用一句sql实现的话test表需要有唯一键
      

  2.   

    select name,(select isnull(sum(1),0)+1 from 表 B where B.name<A.name) from 表 A
      

  3.   

    --如果name是不重复的,可以根据name来生成select 序号=(select count(*) from 表 where name<=a.name),*
    from 表 a
      

  4.   

    根据主键,主键不回重复,
    select a.* ,ind=(select count(*) from test b where a.pk1+a.pk2+..+a.pkn>b.pk1+b.pk2+..+b.pkn)from test a
    --pk1,pk2..pkn是组合键,如果是单主键盘直接根据主键查询
      

  5.   


    根据主键,主键不回重复,
    select a.* ,ind=(select count(*) from test b where a.pk1+a.pk2+..+a.pkn>b.pk1+b.pk2+..+b.pkn)from test a
    --pk1,pk2..pkn是组合键,如果是单主键盘直接根据主键查询