gpt4 book ai didi

MySQL 在同一查询中选择和更新

转载 作者:行者123 更新时间:2023-11-29 07:42:37 25 4
gpt4 key购买 nike

是否可以选择并连接一个表,然后更新该表?

我基本上希望将特定供应商拥有的所有产品的价格提高 5%。问题是定价详细信息与产品本身保存在单独的表中。

我知道这个语法不正确,但它会给你我想要实现的目标的要点:

update 
products_quantity_pricing set price = price + (price/100*5)
where (select
products.supplier_id,
products_quantity_pricing.price
from products
join
products_quantity_pricing on products_quantity_pricing.product_id = products.id
where products.supplier_id = 7 )

最佳答案

您将JOIN直接放入UPDATE查询中:

UPDATE products_quantity_pricing AS pqp
JOIN products AS p ON pqp.product_id = p.id
SET price = price + (price/100*5)
WHERE p.supplier_id = 7

关于MySQL 在同一查询中选择和更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28625054/

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