将数据从一个表复制到另一个表时出现问题。有很多解决方案,但我的问题是不同的。我有两个表Database
和sku
。我必须将数据从shipping_skudetails
复制到shipping_skudetails
,为此,我要这样做,
sku
现在问题是将值复制到不同的列中,
INSERT INTO shyplite.sku
SELECT SkuDetailsId as id,
sku,
seller_id as sellerID,
itemName as name,
itemLength as length,
itemWidth as width,
itemHeight as height,
itemWeight as weight,
modeType_id as mode
FROM shyplitelivedb.shipping_skudetails;
+----+---------+----------+-------------+--------+-------+--------+--------+------+
| id | sku | sellerID | name | length | width | height | weight | mode |
+----+---------+----------+-------------+--------+-------+--------+--------+------+
| 1 | Sample | 1 | SampleItem | 1 | 1 | 1 | 1 | 1 |
| 2 | Sample | 2 | Sample1 | 1 | 1 | 1 | 1 | 1 |
| 3 | SDGS046 | 1 | Shivaprasad | 1 | 1 | 3 | 1 | 2 |
+----+---------+----------+-------------+--------+-------+--------+--------+------+
shyplite.sku
+--------------+---------+-----------+-------------+------------+------------+------------+-----------+
| SkuDetailsId | sku | seller_id | itemName | itemLength | itemWeight | itemHeight | itemWidth |
+--------------+---------+-----------+-------------+------------+------------+------------+-----------+
| 1 | Sample | 1 | SampleItem | 1 | 1.000 | 1 | 1 |
| 2 | Sample | 2 | Sample1 | 1 | 1.000 | 1 | 1 |
| 3 | SDGS046 | 1 | Shivaprasad | 1 | 3.000 | 1 | 1 |
+--------------+---------+-----------+-------------+------------+------------+------------+-----------+
shyplitelivedb.shipping_skudetails
我希望将数据列复制到列。不是通过在查询中安排列。
我想要一个通过识别列名来复制数据的查询。
答案 0 :(得分:1)
试试这个
INSERT INTO shyplite.sku (id, sku, sellerID, name, length, width, height, weight, mode)
SELECT SkuDetailsId as id,
sku,
seller_id as sellerID,
itemName as name,
itemLength as length,
itemWidth as width,
itemHeight as height,
itemWeight as weight,
modeType_id as mode
FROM shyplitelivedb.shipping_skudetails;