declare @t table(a varchar(5)) insert @t select 'A' union all select 'A' union all select 'A' union all select 'B' union all select 'B' union all select 'B' union all select 'C' union all select 'C' declare @i int,@var varchar(5) set @i=0 update @t set @i=case a when @var then @i+1 else 1 end, @var=case a when @var then @var else a end, a=a+'_'+cast(@i as varchar)select * from @t结果就是楼主要的
insert @t
select 'A' union all
select 'A' union all
select 'A' union all
select 'B' union all
select 'B' union all
select 'B' union all
select 'C' union all
select 'C'
declare @i int,@var varchar(5)
set @i=0
update @t
set @i=case a when @var then @i+1 else 1 end,
@var=case a when @var then @var else a end,
a=a+'_'+cast(@i as varchar)select * from @t结果就是楼主要的