只能想到这个傻办法 :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'
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
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
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'
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
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