update tablename set ID=???  where Name=team1
想让符合条件的Name为Team1的所有ID按序列重新填充,怎么实现呢?
就是说team1的ID想更新为1,2,3,4,……
谢谢啦,帮个忙撒

解决方案 »

  1.   


    --建立测试环境
    set nocount on
    create table test(id varchar(20),name varchar(20),time varchar(20))
    insert into test select '1','a','2008-01-01'
    insert into test select '1','a','2005-01-01'
    insert into test select '1','a','2002-01-01'
    insert into test select '1','a','2009-01-01'
    go
    --测试
    update test set id=(select count(*)+1 from test where id=a.id and time<a.time)
    from test a where name='a'
    select * from test order by id
    --删除测试环境
    drop table test
     set nocount off/*----结果
    1 a 2002-01-01
    2 a 2005-01-01
    3 a 2008-01-01
    4 a 2009-01-01
    */