我试图在产品子组中创建一个累计收入,并按顺序递增折扣。
我使用了以下查询
Update Z_Discount_Tool1 Set Cum_Net_Revenue_Discount =
(Select Sum([Umsatz_Netto]) Over (Partition by [WUGR_act] Order by [Discount] From Z_Discount_Tool1)
但是,我收到以下错误消息
子查询返回的值超过1。当子查询遵循=,!=,<,< =,>,> =或子查询用作表达式时,不允许这样做。
我在代码中找不到错误。所以任何帮助都表示赞赏。提前谢谢!
答案 0 :(得分:1)
这看起来像SQL Server。您可以使用可更新的CTE:
with toupdate as (
select dt.*,
Sum([Umsatz_Netto]) Over (Partition by [WUGR_act] Order by [Discount]) as new_Cum_Net_Revenue_Discount
from Z_Discount_Tool1 dt
)
Update toupdate
Set Cum_Net_Revenue_Discount = new_Cum_Net_Revenue_Discount;