Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mysql中的update语句_Mysql_Subquery - Fatal编程技术网

mysql中的update语句

mysql中的update语句,mysql,subquery,Mysql,Subquery,我想将新数量(100)添加到产品的现有数量。 这给了我一个这样的错误 '不能在FROM子句中为更新指定目标表'product'' 如何修复此问题???您只需执行以下操作: update product set qty=100 + (select qty from product p where p.name='abc' and p.weight='100g') where name='abc' and weight='100g' update product set qty= qty +

我想将新数量(100)添加到产品的现有数量。 这给了我一个这样的错误

'不能在FROM子句中为更新指定目标表'product''


如何修复此问题???

您只需执行以下操作:

update product 
set qty=100 + (select qty from product p  where p.name='abc' and p.weight='100g')
where name='abc' and weight='100g'
update product 
set qty= qty + 100
where name='abc' and weight='100g'