我在 SQL Server 中有 2 个表:
两个表之间的关系是
Table1.CUSTOMER_ID
匹配 Table2.CUSTOMER_KID
。对于 Table2,CUSTOMER_KID
列中的每个值在 PRICE
列中都有多个具有不同产品的记录。
我需要一个查询来显示表 1 中的 ID 和城市以及表 2 中的总信息。我该怎么做?
SELECT t1.Customer_ID, t1.Customer_City, sum(t2.Price)
FROM Table1 t1
INNER JOIN Table2 t2 ON t2.Customer_KID = t1.Customer_ID
GROUP BY t1.Customer_ID, t1.Customer_City