gpt4 book ai didi

使用 WHERE 更新 MySQL 交叉表

转载 作者:可可西里 更新时间:2023-11-01 07:45:14 26 4
gpt4 key购买 nike

下面是一个简单的查询,用于使用来自 helper 的数据更新表 product

UPDATE product p 
INNER JOIN helper h ON p.productcode = h.productcode
SET p.picture = h.picture;

但如果我在末尾添加 WHERE p.gotpicture=0 以仅更新 p.gotpicture=0 的记录而不是整个表,则查询更新 0 行。为什么?

最佳答案

我有测试人员,它对我来说工作正常。

但是你可以测试这些:

UPDATE product p , helper h
SET p.picture = h.picture
WHERE p.gotpicture=0
AND p.productcode = h.productcode;

或者

UPDATE product p 
SET p.picture = (select h.picture from helper h where p.productcode = h.productcode)
WHERE p.gotpicture=0
AND p.productcode in (select h.productcode from helper h);

关于使用 WHERE 更新 MySQL 交叉表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17087948/

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