简体   繁体   English

将一个数据库表的值迁移到另一个具有不同列的表中

[英]Migrate values of one database table into another table with different columns

I'm new to SQL, so I think this will have a simple answer, but I'm having trouble tracking down a comparable example via google. 我是SQL的新手,所以我认为这将是一个简单的答案,但我在通过Google跟踪可比较的示例时遇到了麻烦。

I have two tables in a SQL database with similar values, but a different number of columns with different column names. 我在SQL数据库中有两个具有相似值的表,但是具有不同列名的列数不同。 I need to migrate the the values from the first database (catalog_product_entity_tier_price) into the second database (mb_tierprices_list) and then fill in the gaps with a default value. 我需要将值从第一个数据库(catalog_product_entity_tier_price)迁移到第二个数据库(mb_tierprices_list),然后使用默认值填充空白。

This is where I'm up to: 这是我要做的:

INSERT INTO catalog_product_entity_tier_price (entity_id, website_id, qty, value) 
SELECT entity_id, website_id, price_qty, percent
FROM mb_tierprices_list;

But I also need to handle three more columns in catalog_product_entity_tier_price with default values: 但是我还需要使用默认值处理catalog_product_entity_tier_price中的其他三列:

value_id (this is set to AUTO_INCREMENT, so nothing to do there)
all_groups = 1
customer_group_id = 0

Should I split this into two queries and just do a second one like so: 我是否应该将其分为两个查询,然后像这样执行第二个查询:

INSERT INTO catalog_product_entity_tier_price (all_groups, customer_group_id) 
VALUES (1, 0);

Is there a preferred way to accomplish this? 是否有实现此目的的首选方法?

Just put the default values in your select like this: 只需将默认值放入您的选择中,如下所示:

INSERT INTO catalog_product_entity_tier_price (entity_id, website_id, qty, value, all_groups, customer_group_id) 
SELECT entity_id, website_id, price_qty, percent, 1, 0
FROM mb_tierprices_list;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将数据库中一个表中的特定行插入到具有不同列的另一个表中 - Insert specific rows from one table in database into another with different columns MySQL:将一个表的部分内容迁移到另一个结构不同的表中 - MySQL: migrate some content of one table into another table with a different structure 当表值位于2个具有不同端口的不同服务器上时,如何从一个MySQL数据库向另一个MySQL数据库插入表值? - How to insert table values from one MySQL database to another MySQL database when they are on 2 different servers with different ports? 用不同的值更新一个数据库表列 - Update one database table column with different values 从一个表到另一列的不同表中检索数据 - Retrieving Data From One Table To Another Table With Different Columns 如何通过在另一个表中作为行给出的值过滤一个表的列? - How to filter columns of one table by values given as rows in another table? 根据mysql中另一个表中的值更新一个表中的多个列 - Update multiple columns in one table based on values in another table in mysql MySQL-将一个表插入另一个数据库中的另一个表 - MySQL- insert one table into another table in a different database 将数据从一个数据库表复制到不同服务器上的另一表 - Copying data from one database table to another table on different servers 从另一个表中选择一个不同的值 - Select different values from one table based on another table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM