如何使用mysql中的vary选项将多条记录从一个表中的某一列复制到一列中的另一个表中
如何使用SQL命令在mysql中使用vary选项从表中的某一列复制多条记录并插入以更新列中的另一个表 列:“targetCategory”条件所有记录都包含Top/name\u test2、Top/name\u test2/% 列“标题”,“父主题”引用数据 注意:数据具有根差异,不导入示例:Top/name\u test752如何使用mysql中的vary选项将多条记录从一个表中的某一列复制到一列中的另一个表中,mysql,database,insert,insert-update,Mysql,Database,Insert,Insert Update,如何使用SQL命令在mysql中使用vary选项从表中的某一列复制多条记录并插入以更新列中的另一个表 列:“targetCategory”条件所有记录都包含Top/name\u test2、Top/name\u test2/% 列“标题”,“父主题”引用数据 注意:数据具有根差异,不导入示例:Top/name\u test752 table_exemple1 ====================================================
table_exemple1
===========================================================================
| aliasID | title | targetCategory | parentTopic |
===========================================================================
No | 1 | name_test752 | Top/name_test752/tel | Top/name_test752 |
---------------------------------------------------------------------------
|-<----| 2 | name_test2 | Top/name_test2 | Top/name_test2 |
| ---------------------------------------------------------------------------
||-<---| 3 | 5 | Top/name_test2/etc/5 | Top/name_test2/etc|
|| ---------------------------------------------------------------------------
|||-<--| 4 | tesla | Top/name_test2/tesla | Top/name_test2 |
||| ----------------------------------------------------------------------------
|||
|||
||| **tabla_exemple2 before update**
||| =====================================================================================================================================================================
||| | id | topic | topicShort | parentTopic | displayName | description | lastUpdate | sitecount |
||| =====================================================================================================================================================================
||| | 1 | Top/name_test/helloo | helloo | Top/name_test752 | Nuul | hello | 2010-06-19 04:10:14 | 324 |
||| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------
||| | 2 | Top/name_test2/nest | nest | Top/name_test2/ | Nuul | nest | 2010-06-19 04:11:23 | 545435 |
||| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------
||| | 3 | Top/name_test2/etc/57 | 5 | Top/name_test2/etc/ | Nuul | 5 | 2010-06-19 04:15:13 | 54354343 |
||| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------
||| | 4 | Top/name_test2/tesla1 | tesla | Top/name_test2/ | Nuul | tesla | 2010-06-19 04:10:14 | 676756 |
||| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------
|||
|||
||| **table_exemple2** after update
|||
|||
||| =====================================================================================================================================================================
||| | id | topic | topicShort | parentTopic | displayName | description | lastUpdate | sitecount |
||| =====================================================================================================================================================================
||| | 1 | Top/name_test/helloo | helloo | Top/name_test752 | Nuul | hello | 2010-06-19 04:10:14 | 324 |
||| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------
||| | 2 | Top/name_test2/nest | nest | Top/name_test2/ | Nuul | nest | 2010-06-19 04:11:23 | 545435 |
||| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------
||| | 3 | Top/name_test2/etc/57 | 5 | Top/name_test2/etc/ | Nuul | 5 | 2010-06-19 04:15:13 | 54354343 |
||| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------
||| | 4 | Top/name_test2/tesla1 | tesla | Top/name_test2/ | Nuul | tesla | 2010-06-19 04:10:14 | 676756 |
||| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------
|||--->| 6 | Top/name_test2 | name_test2 | Top | Nuul | name_test2 | insert data | 0 |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------
|----->| 7 | Top/name_test2/etc/5 | 5 | Top/name_test2/etc | Nuul | 5 | insert data | 0 |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------
|----->| 8 | Top/name_test2/tesla | tesla | Top/name_test2 | Nuul | tesla | insert data | 0 |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Data from "targetCategory" wil goo to "topic"
data from "title" goo to "topicShort"
Data from "parentTopic" goo to "parentTopic"
I ned insert new data to column "displayName" well be "Nuul"
I ned insert new data to column "description" well be idem "topicShort"
I ned insert new data to column "displayName" well be "Nuul"
I ned insert new data to column "lastUpdate" well be "data time inserition"
I ned insert new data to column "displayName" well be "0"
condition its column targetCategory data like Top/name_test2 and like Top/name_test2/%
表\u示例1
===========================================================================
|别名ID |标题|目标类别|父主题|
===========================================================================
否| 1 |姓名|测试752 | Top/name |测试752/tel | Top/name |测试752|
---------------------------------------------------------------------------
|-|8 | Top/name|u test2/tesla | tesla | Top/name|u test2 | Nuul | tesla |插入数据| 0|
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
从“targetCategory”到“topic”的数据
从“标题”goo到“主题短片”的数据
从“parentTopic”goo到“parentTopic”的数据
我需要在“displayName”列中插入新数据,该列将为“Nuul”
我需要在“说明”列中插入新数据,并将其视为“主题短”
我需要在“displayName”列中插入新数据,该列将为“Nuul”
我需要在“lastUpdate”列中插入新数据,而不是“数据时间插入”
我需要在“displayName”列中插入新数据,该列可能为“0”
将其列targetCategory数据设置为Top/name_test2和Top/name_test2/%
不完全清楚您想要什么,但您可以与适当的一起使用。例如,要从列2
中删除所有内容,直到第一个冒号:
INSERT INTO table_exemple3 (column4, column5, column6)
SELECT column1, SUBSTRING(column2, LOCATE(':', column2) + 1), column3
FROM table_exemple2
请参阅。您如何确定希望复制到
表例2
中的表例1
中的哪些记录?您如何确定带有表例2.id=6
的新记录的值,该记录似乎与表例1
中的任何原始记录几乎没有相似之处?如果根不同的示例Top/name\u test50已经不需要了,我不想创建重复的记录6
hastopic='Top/name\u test2/32'
和topicShort='32'
;根据您的映射,这些值应该分别来自targetCategory
和title
,但没有任何记录在表中的示例1
中有这些值:)是的,这是我的错,所以你现在明白了,好吧,你有解决方案了吗?你看到我下面答案中的SQLFIDLE链接了吗?@olariuromevicentiu:你想要类似的东西吗?