SQL - 从两个表格中乘以两列

时间:2017-10-10 16:45:54

标签: sql sql-server-2005

我需要将表A中的产品值乘以表b中的购买量,并将SUM写入表B中的列。

table a
--------
product
value
table b
--------
memberID
freuency of purchase of product
Sum of purchases

1 个答案:

答案 0 :(得分:0)

我认为这样的事情应该有用,如果你有两个表之间的关系,比如两个表中的productID,或者类似于此,试试看

Select tA.ProductsValue * tB.TotalPurchases as TotalMoney , ProductID

From TableA  ta
Join ( select Count(purchases) as TotalPurchases, productID   
       from tableB
       Group by ProductID 
      ) tB on tA.ProductID = tB.ProductID 
相关问题