我對SQL仍然很陌生,遇到問題。我正在使用經典Northwind數據庫的變體。我正在使用Microsoft SQL Server Management Studio。SQL INNER JOIN - 連接中的列名也在選擇*錯誤*
這裏的問題是:
/*
Join Products and ProductVendors to display by product, the product
number, the average wholesale price, and the average retail price.
*/
下面是我有:
SELECT Products.productNumber As [Product Number],
CAST(AVG(wholesalePrice) as decimal (8,2)) As [Average Wholesale Price],
CAST(AVG(retailPrice) as decimal (8,2)) As [Average Retail Price]
FROM Products INNER JOIN ProductVendors
ON Products.productNumber = ProductVendors.productNumber
這是我得到的錯誤:
消息8120 ,等級16,狀態1,行2
列'Products.productNumber'在選擇列表中無效,因爲它不包含在聚合函數或GROUP BY子句中。
GROUP BY
條款是MySQL或MS SQL服務器? – Alex使用:.... group by Products.productNumber,wholesale價格,retailPrice – apomene
絕對不是mysql - 它無法關心如果所有的選擇字段都在'group by' –