日期:2014-05-17 浏览次数:20509 次
create table tb(id int,val varchar(10),id2 int)
insert into tb(id,val)
select 80,'i'
union all select 80,'h'
union all select 80,'j'
union all select 80,'g'
union all select 80,'p'
union all select 80,'x'
union all select 80,'q'
union all select 90,'k'
union all select 90,'h'
union all select 90,'i'
union all select 90,'m'
union all select 90,'t'
union all select 90,'y'
declare @i int,@id int
set @id=0
set @i=1
update tb
set @i=case when @id=id then @i+1 else 2 end,@id=case when @id=id then @id else id end,id2=@i
select * from tb
drop table tb