原文:https://blog.csdn.net/CHENHAO19900918/article/details/79869330
功能描述
写一条update语句,update的值 为 统计关联表的 “金额和数量” 这两个字段
sql语句
--更新主表字段 ContractNum、ContractAmount
UPDATE dbo.ProjectInventory
SET ContractNum=(
SELECT ISNULL(SUM(ContractNum),0) FROM dbo.InventorySubitemRelation WHERE InventoryId=ProjectInventory.Id
)
, ContractAmount=(
SELECT ISNULL(SUM(ContractAmount),0) FROM dbo.InventorySubitemRelation WHERE InventoryId=ProjectInventory.Id
)