【发布时间】:2018-11-05 17:27:50
【问题描述】:
我正在通过以下查询更新记录:
update tableA set Quantity=
(select count(*) from table B where ID=x)
where ID=x
update tableA set Quantity=
(select sum(Stock) from table C where ID=y)
where ID=y
示例(已更正):
tableA 中的所有 ID 都分为 2 个表:TableB 和 TableC。我必须用 TableB 的计数更新 TableA 的数量字段(如果 ID.TableA 在 TableB 中),并用 TableC 的 sun(stock) 更新 TableA 的数量字段(如果 ID.TableA 在 TableC 中)
有 500k 个 ID 需要像这样更新。我想知道如何在不必执行 500k 查询的情况下完成它。
编辑:我正在从 TableB 中获取行数,count 不是 TableB 的列。
任何帮助将不胜感激,TIA!
【问题讨论】:
-
如果
ID既不在tableB也不在tableC中怎么办?使用空值、零、不更新、其他? -
所有ID都在TableB或TableC中
标签: sql database db2 sql-update