mySql 将行复制到同一个表中,键值已更改(不覆盖现有)

mySql copy rows into same table with key value changed (not overwriting existing)(mySql 将行复制到同一个表中,键值已更改(不覆盖现有))
本文介绍了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 将行复制到同一个表中,键值已更改(不覆盖现有)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)