在运行此查询时,我得到了表的以下错误更新列名称:
update t1 set t1.DIST_= (SELECT SUM(t2.amount) as DIST_ FROM t2
WHERE unique_number =300291 and t2.reseller_id ='31')
我有2个表(t1和t2) t1的列为DIST_,unique_number和1行 t2的行和列数量很多,unique_number,reseller_id
此请求必须使用t2.reseller_id = '31'从表t2计算金额,并通过unique_number将值写入t1.DIST _
现在请求更改所有表列的值,但是我只需要更新t2.unique_number = t1.unique_number
处的列答案 0 :(得分:1)
在email
语句中需要一个WHERE
子句:
UPDATE
如果要将update t1 set t1.DIST_= (SELECT SUM(t2.amount) as DIST_ FROM t2
WHERE unique_number =300291 and t2.reseller_id ='31')
where t1.unique_number = 300291
的所有行更新为t1
的相应总和,请与对它们进行分组的子查询一起加入。
t2
答案 1 :(得分:0)
使用连接尝试如下所示
UPDATE TABLEA t1
JOIN (SELECT unique_number,SUM(t2.amount) as DIST_ FROM table2
group by unique_number
) t2 ON t2.unique_number=t1.unique_number
SET t1.DIST_ =t2.DIST_