我有三个名为1的表:site_stock,2:item_add,3:stock_add。现在我想更新site_stock它的值应该是item_add初始余额和stock_add项目数量的总和我已尝试此查询但它给了我错误"操作必须使用可更新查询"
UPDATE site_stock
SET quantity = ((select sum(sa.quantity) from stock_add as sa where sa.item_code='J-110') +
(select sum(ia.quantity) from item_add as ia where ia.item_code='J-110'))
WHERE item_code='J-110' and site_id=1;
答案 0 :(得分:1)
UPDATE ((site_stock inner join item_add on site_stock.item_code=item_add.item_code) left join stock_add on site_stock.item_code=stock_add.item_code ) SET site_stock.quantity =(item_add.quantity + (iif(stock_add.quantity is null,0,stock_add.quantity))) WHERE item_add.item_code=site_stock.item_code and site_stock.site_id=1;