这是
我尝试使用函数的sqlfiddle 链接。 它仅在查询中起作用,但是当我在查询的子查询中尝试此操作时,它给出了错误的值。这是我的查询sum()
SELECT
UPDATE
SELECT
SELECT
sum(i.pr_pur_cost_price*i.quantity) AS net_amount
FROM
product_purchases AS p
LEFT JOIN
product_purchase_item AS i
ON
p.product_purchase_item_id=i.product_purchase_item_id
WHERE
p.insert_operation=48
GROUP BY
p.insert_operation
这里我的更新查询
UPDATE
shop_balance AS s
SET
s.shop_balance=(s.shop_balance-(
SELECT
sum(i.pr_pur_cost_price*i.quantity) as net_amount
FROM
product_purchases AS p
LEFT JOIN
product_purchase_item AS i
ON
p.product_purchase_item_id=i.product_purchase_item_id
WHERE
p.insert_operation=48
GROUP BY
p.insert_operation
)
)
where s.shop_balance_id=n;
为什么 UPDATE 查询中有这个错误的值。sum() 函数中的两列有问题吗?或任何最佳解决方案?