当我更新相同的表列时,计算另一列值

时间:2017-04-18 07:19:18

标签: sql oracle11g oracle10g

Update dp2 a set a.amt= (select((b.qty*b.rate)-b.discount) from dp2 b where a.dpinheadid=b.dpinheadid)

错误来了

ORA-01427: single-row subquery returns more than one row
#For.Ex: TABLES DP2 A,DP2 B
(b.qty*b.rate)-b.discount) THIS VALUE Update TO This column A.AMT

2 个答案:

答案 0 :(得分:0)

问题是您尝试使用select语句更新行,该语句返回超过1行

此选择:

select((b.qty*b.rate)-b.discount) from dp2 b where a.dpinheadid=b.dpinheadid

返回多于1个结果 - 因此您无法将其用作更新值。

如果您想使用它,则需要它返回单个值,因此请尝试使用WHERE子句或TOP 1仅返回第一个结果等

答案 1 :(得分:0)

您是否尝试过此查询:

Update dp2 a set a.amt= a.qty*a.rate-a.discount 
相关问题