我运行以下SQL代码时显示此错误?我试图通过子查询来解决这个代码

时间:2017-07-02 07:15:17

标签: sql sql-server tsql sql-server-2012

loadDashboardItems

但显示此错误

  

Msg 8120,Level 16,State 1,Line 1   专栏' Customer.CustomerName'在选择列表中无效,因为它不包含在聚合函数或GROUP BY子句中。

1 个答案:

答案 0 :(得分:1)

您忘记指定group by子句,请尝试:

Select c.CustomerName, pl.ProductName as 'Product Name', o.OrderDate as 'Order date', 
Count([Address]) as 'No of Places', SUM(pl.Price * od.OrderQty) as 'Total Amount'
From Customer c
Inner Join [Order] o ON o.CustomerId = c.CustomerID
Inner Join OrderDetails od ON od.OrderId = o.OrderID
Inner Join ProductList pl ON pl.ProductID = od.ProductId
Inner join Customer cc on c.CustomerID=cc.CustomerID and cc.CustomerName = 'Mr.A'
group by c.CustomerName, pl.ProductName, o.OrderDate