本文介绍了mySql将行复制到键值已更改的同一表中(不覆盖现有表)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何复制mySql表中的选定行并在键值已更改的情况下插入.我可以在同一查询中进行选择并插入吗?

确切地说,我想要的内容如下:

表格列,ID和ISO3是键:

+----+------+-------------------------+
| ID | ISO3 |          Text           |
+----+------+-------------------------+
|  1 | ENU  | A text in english       |
|  2 | ENU  | Another text in english |
|  3 | ENU  | bla bla                 |
|  1 | JPN  | 与えられた枠             |
+----+------+-------------------------+

插入后,我希望我的表看起来像这样:

+----+------+---------------------------+
| ID | ISO3 |           Text            |
+----+------+---------------------------+
|  1 | ENU  | A text in english         |
|  2 | ENU  | Another text in english   |
|  3 | ENU  | bla bla                   |
|  1 | JPN  | 与えられた枠               |
|  2 | JPN  | Another text in english   |
|  3 | JPN  | bla bla                   |
+----+------+---------------------------+
解决方案
INSERT INTO your_table (ID, ISO3, TEXT)
SELECT ID, 'JPN', TEXT
FROM your_table
WHERE ID IN ( list_of_ id's )

如果要在一个单元格中更改值,只需对值进行硬式输入即可,而不是从表中进行选择(就像我对'JPN '所做的那样). /p>

How do I copy a selection of rows from a mySql table and insert with just the key value changed. Can I do a select and insert in same query?

To be precise, what I want would look like this:

Table cols, ID and ISO3 are keys:

+----+------+-------------------------+
| ID | ISO3 |          Text           |
+----+------+-------------------------+
|  1 | ENU  | A text in english       |
|  2 | ENU  | Another text in english |
|  3 | ENU  | bla bla                 |
|  1 | JPN  | 与えられた枠             |
+----+------+-------------------------+

After the insert I want my table to look like this:

+----+------+---------------------------+
| ID | ISO3 |           Text            |
+----+------+---------------------------+
|  1 | ENU  | A text in english         |
|  2 | ENU  | Another text in english   |
|  3 | ENU  | bla bla                   |
|  1 | JPN  | 与えられた枠               |
|  2 | JPN  | Another text in english   |
|  3 | JPN  | bla bla                   |
+----+------+---------------------------+
解决方案
INSERT INTO your_table (ID, ISO3, TEXT)
SELECT ID, 'JPN', TEXT
FROM your_table
WHERE ID IN ( list_of_ id's )

If you want to change a value in one cell, just hard-type the value instead of selecting from table (like I did with 'JPN').

这篇关于mySql将行复制到键值已更改的同一表中(不覆盖现有表)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 00:10