本文介绍了mySql 将行复制到同一个表中,键值已更改(不覆盖现有)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从 mySql 表中复制选择的行并在仅更改键值的情况下插入.我可以在同一个查询中进行选择和插入吗?
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:
表格列、ID 和 ISO3 是键:
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 )
如果您想更改一个单元格中的值,只需硬输入值而不是从表格中选择(就像我使用 'JPN' 所做的那样).
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 将行复制到同一个表中,键值已更改(不覆盖现有)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!