我有两张桌子。
Customer ID, NAME, MonthlyIncome
Orders ID, CustomerKey, TotalCost
我想把这两张桌子合二为一,就像在商店里买的总金额一样。
CustomerKey, MonthlyIncome, TotalCost.
我试图按 分组CustomerKey
,但我无法包括其余的列。我应该使用哪个查询?
SELECT
fs.CustomerKey, SUM(fs.TotalCost) as TotalBought
FROM
FactOnlineSales fs
INNER JOIN
DimCustomer c on c.CustomerKey = fs.CustomerKey
GROUP BY
fs.CustomerKey