gpt4 book ai didi

mysql - 在查询中将数据表复制到没有列指定的表

转载 作者:行者123 更新时间:2023-11-28 23:16:05 25 4
gpt4 key购买 nike

我在将数据从一个表复制到另一个表时遇到问题。找到了很多解决方案,但我的问题有所不同。我有两个表 skushipping_skudetails。我必须将数据从 shipping_skudetails 复制到 sku,为此,

INSERT INTO test.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 testdb.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 |
+----+---------+----------+-------------+--------+-------+--------+--------+------+
test.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 |
+--------------+---------+-----------+-------------+------------+------------+------------+-----------+

testdb.shipping_skudetails

现在的问题是值被复制到不同的列中,

(like :  shipping_skudetails.itemWeight copied into test.width)

我想将数据列复制到列。不是通过排列查询中的列。

I want a query that copy data by identifying column name.

最佳答案

试试这个

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;

关于mysql - 在查询中将数据表复制到没有列指定的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43818113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com