我有两个
Order
带有列的表:
OrderID,OrderDate,CID,EmployeeID
并OrderItem
带有列:
OrderID,ItemID,Quantity,SalePrice
我需要返回 CustomerID(CID)、每个客户的订单数量以及所有订单的每个客户的总金额。
到目前为止,我有两个单独的查询。一个给我客户订单的数量....
SELECT CID, Count(Order.OrderID) AS TotalOrders
FROM [Order]
Where CID = CID
GROUP BY CID
Order BY Count(Order.OrderID) DESC;
另一个给我总销售额。我很难将它们组合在一起...
SELECT CID, Sum(OrderItem.Quantity*OrderItem.SalePrice) AS TotalDollarAmount
FROM OrderItem, [Order]
WHERE OrderItem.OrderID = [Order].OrderID
GROUP BY CID
我在 Access 2010 中执行此操作。