如何通过聚合来自另一个 table 中另一列的数据来创建派生列

how to I create a derived column by aggregate data from another column in another table

我有 2 tables :

Book(Name,quantity,supplier)
SuppliedBy (supplier,quantity)

我希望 SuppliedBy table 中的数量与该供应商提供的书籍数量相等,所以我写了一个 set 语句

update supplier
set supplier.quantity = (select quantity 
                         from (select sum(quantity) as quantity, SuppliedBy 
                               from book group by SuppliedBy) a
                         where a.SuppliedBy = supplier.SuppliedBy)

但是我想在添加新书时自动更新 SuppliedBy 中的数量值。请帮忙

我认为您需要在 Book table 上创建一个 after insert 触发器来更新 supliedBy table.

中的值