无法从此查询中获取结果。我究竟做错了什么?

时间:2014-04-07 03:49:27

标签: sql subquery northwind

写一个子查询,返回客户用的订单总数 订单数量最多。包括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'。

???

1 个答案:

答案 0 :(得分:0)

OrderItems是Northwind数据库的成员还是其他地方的成员?您可能必须使用[DatabaseName].dbo.[OrderItems]

完全限定它