当前位置: 代码迷 >> Sql Server >> 请问updata,多谢
  详细解决方案

请问updata,多谢

热度:72   发布时间:2016-04-27 21:06:03.0
请教updata,谢谢
数据库的数据
字段1       字段2
a               0
a               0
a               0
a               0
a               0

更新后的结果为
字段1       字段2
a               10
a               5
a               5
a               5
a               5




------解决方案--------------------
什么规律?
------解决方案--------------------
select id = identity(int,1,1) , * into b from a
update b
set 字段2 = 10 where id = 1
update b
set 字段2 = 5 where id <> 1

delete from a
insert into a(字段1,字段2) select 字段1,字段2 from b

drop table b

------解决方案--------------------
:)