| Table [A] | Table [B]
---------------------- ---------------------
| |
| id value data | id value data
| ab 15 100 | ac 19 200
| ab 18 101 | ac 28 310
| ab 22 199 | ac 39 401
表 A 是我的旧数据库表,其中包含历史数据。 表 B 是我当前的数据库表,id 中具有更正值
我想将表 A 中的历史数据插入表 B 中,其中 value<=xxxx AND value >=xxxx,同时在插入表 B 时设置 tablea.id = ac 中的数据,以便数据结果将会是。
| Table [A] | Table [B]
-------------------- ----------------------
| |
| id value data | id value data
| ab 15 100 | ac 19 200
| ab 18 101 | ac 28 310
| ab 22 199 | ac 39 401
| | ac 15 100
| | ac 18 101
| | ac 22 199
我将使用 INSERT IGNORE,因为我的表有 3 列,因为它是复合主键。表描述只是一个示例。我的表有很多列,只是突出显示我想要完成的数据导入的主要区别。
最佳答案
这是你想要的吗?
insert into tableb (id, value, data)
select 'ac', value, data
from tablea
where id = 'ab';
这将插入值并将 id
从 'ab'
更改为 'ac'
。
关于mysql - 将数据从表 A 插入表 B WHERE(条件)& SET Col.a = "xxx",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31829947/