我需要对来自多个表的数据进行复杂的求和,但我不知道该怎么做。
这是我的桌子
[Article]
ArticleId     Description     NetPurchase
1001          Shoe            500
1002          Box             100
[Product]
ProductId     Description     NetPurchase
3001          Shoe in Box     ?
[ProductArticle]
ProductArticleId     ArticleId     ProductId     Qty
1                    1001          3001          5
2                    1002          3001          2
Product 中的 NetPurchase 应该对 ProductArticle 中属于产品 3001 的所有文章求和。在本例中 (500*5 + 100*2) = 2700
说明:我想对 Product 中的所有行进行 SQL UPDATE,它应该加入 ProductArticle 以使用 NetPurchase 获取所有相关文章,并与 ProductArticle 中的 Qty 相乘。它应该将所有这些与 Product.NetPurchase 相加