[英]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.