我尝试使用乘法更新字段,但显示错误#1093 - Table is specified twice, both as a target for 'UPDATE' and as a separate source for data
这是我的查询
UPDATE `order_details` SET `price` =
(SELECT (od.quantity * p.pricePerUnit)
FROM order_details od join products p ON od.id_product = p.id_product
WHERE dp.id_product = p.id_product)
有没有解决方案?
答案 0 :(得分:1)
你不可能在MySQL中做到这一点。最好的方法是JOIN
:
UPDATE order_details od JOIN
products p
ON od.id_product = p.id_product
SET price = od.quantity * p.pricePerUnit;