写一个子查询,返回客户用的订单总数 订单数量最多。包括customerid和下达的订单数量。
USE Northwind
GO
SELECT CustomerID,
COUNT(Orders.OrderID) AS TotalOrders,
SUM(OrderAmounts.DollarAmount) AS TotalDollarAmount
FROM [Orders]
Left Outer JOIN (SELECT OrderID, Sum(Quantity*SalePrice) AS DollarAmount
FROM OrderItems GROUP BY OrderID) AS OrderAmounts
ON Orders.OrderID = OrderAmounts.OrderID
GROUP BY CustomerID
ORDER BY Count(Orders.OrderID) DESC
我得到了这样的答复: Msg 208,Level 16,State 1,Line 1 无效的对象名称'OrderItems'。
???
答案 0 :(得分:0)
表OrderItems
是Northwind数据库的成员还是其他地方的成员?您可能必须使用[DatabaseName].dbo.[OrderItems]