id order group
1          a
2          a
3          b
4          c
5          a
现在要增加排序
变成
id order group
1   1       a
2   2       a
3   1       b
4   1       c
5   3       a

解决方案 »

  1.   

    只能想到这个傻办法 :update  tablename  set order='1' where id='1'
    update  tablename  set order='2' where id='2'
    update  tablename  set order='1' where id='3'
    update  tablename  set order='1' where id='4'
    update  tablename  set order='3' where id='5'
      

  2.   

    create table c([id] int,[group] varchar(10))
    insert c select 1,'a'
    union all select 2,'a'
    union all select 3,'b'
    union all select 4,'c'
    union all select 5,'a'
    select *,(select count(*)+1 from c where [group]=t.[group] and id<t.id) from c t
      

  3.   

    create table c([id] int,[group] varchar(10))
    insert c select 1,'a'
    union all select 2,'a'
    union all select 3,'b'
    union all select 4,'c'
    union all select 5,'a'
    alter table c add qq int 
    update c set qq=(select  count(*)+1 from c a where a.[group]=c.[group] and a.id<c.id)
    select * from  c 
    drop table c