SQL:如何通过计算更新所有行?

cam*_*lly 1 sql t-sql sql-server sql-update

我想在添加total price了基于该顺序比萨饼秩序sub-totaltax.我一直在收到错误,说明子查询使用此命令返回的值超过1:

DECLARE @orderTotal AS INT
SET @orderTotal = (SELECT(SUM((orderSubtotal+tax) * (1 - discountAmount)))
                   FROM OrderProcessing GROUP BY orderID)
UPDATE OrderProcessing
SET orderTotalAmount = @orderTotal
Run Code Online (Sandbox Code Playgroud)

discountAmount等于0.2表示20%折扣的十进制数.

Zoh*_*led 5

首先,这是错误的方法,除非您希望所有订单在orderTotalAmount列中具有相同的值.
我想你可能正在寻找这样的东西:

UPDATE OrderProcessing
SET orderTotalAmount = (orderSubtotal + tax) * (1 - discountAmount)
Run Code Online (Sandbox Code Playgroud)

其次,我认为你的第一个查询中有太多括号.