你是不是想保留原数据,所以不能用update --把name='aaa'的数据复制到name='bbb' insert into A select ID, 'bbb' as Name, Age, Address from A where Name = 'aaa'
不必非得查出来吧 update A set name = ... where ....如果大批量修改,且不同值的话,可通过临时表B, 把要更改的数据放到临时表B中, 让后通过ID建立连接 update A set name = (select name from B where A.id = B.id) where exists (select 1 from B where B.id = A.id)
也许楼主的意思如3楼所说的,原来的数据不变,只是将name字段修改为其他值,然后insert到该表--把name='aaa'的数据将name改为'bbb',其他字段不变,再插入表 insert into A select ID, 'bbb' as Name, Age, Address from A where Name = 'aaa';
--把name='aaa'的数据复制到name='bbb'
insert into A
select ID, 'bbb' as Name, Age, Address from A
where Name = 'aaa'
update A set name = ... where ....如果大批量修改,且不同值的话,可通过临时表B,
把要更改的数据放到临时表B中,
让后通过ID建立连接
update A set name = (select name from B where A.id = B.id) where exists (select 1 from B where B.id = A.id)
insert into A
select ID, 'bbb' as Name, Age, Address from A
where Name = 'aaa';