我有3张桌子。
1.Customers Table(CustomerID,CustomerName)
2.SalesTable(SalesChannel,CustoemrID,SalesID)
3.TransactionTable(SalesID,UnitsSold,TotalAmount,SellingDate)
现在我需要每个客户每个月的总销量和总销量? 请帮我解决这个问题?
答案 0 :(得分:0)
SELECT C.CustomerID
,C.CustomerName
,MONTH(t.SellingDate) AS SalesMonth
,SUM(t.UnitsSold * t.TotalAmount) AS TotalSales
FROM Customers C
INNER JOIN SalesTable S ON S.CustomerID = C.CustomerID
INNER JOIN TransactionTable t ON t.SalesID = S.SalesID
GROUP BY C.CustomerID ,C.CustomerName ,MONTH(t.SellingDate)