--将数据插入临时表
select [ID]=indetity(int,1,1)
,*
into #
from 表--产生序号
update #
set B=(select count(1) from # where A=t.A and ID<t.ID)
from # t--回写数据
truncate table 表
insert 表
select A,B from #--删除临时表
drop table #
select [ID]=indetity(int,1,1)
,*
into #
from 表--产生序号
update #
set B=(select count(1) from # where A=t.A and ID<t.ID)
from # t--回写数据
truncate table 表
insert 表
select A,B from #--删除临时表
drop table #
T
set
@B = case when @A=A then @B+1 else 0 end,
B = @B,
@A = A
alter table t1 add id int identity(1,1)
select a,(select count(*) from t1 b where b.a=a.a and b.id>a.id) b from t1 a order by a,b
alter table t1 drop column id
http://community.csdn.net/Expert/topic/3313/3313287.xml?temp=.8957178