我有两张桌子:
new_product
包含列:
id_product,
id_category,
id_combination,
id_feature,
whole_sale_price,
retail_price,
old_product
包含列:
id_product,
id_category,
id_combination,
id_feature,
whole_sale_price,
retail_price,
如何使用来自{{1}的whole_sale_price
和retail_price
列的值更新new_product
上的whole_sale_price
和retail_price
列中的数据使用密钥old_product
,id_category
和id_combination
?
答案 0 :(得分:0)
一般来说,您可以按如下方式编写:
UPDATE
table1 AS target,
(SELECT column1, column2 FROM table2) AS source
SET
target.column3 = source.column1
WHERE
target.column4 = source.column2
答案 1 :(得分:0)
如果您想更新whole_sale_price
和retail_price
,可以使用此查询:
UPDATE new_product as newP
JOIN old_product as oldP
ON newP.id_category = oldP.id_category AND
newP.id_combination = oldP.id_combination AND
newP.id_feature = oldP.id_feature
SET newP.whole_sale_price = oldP.whole_sale_price,
newP.retail_price = oldP.retail_price