简体   繁体   English

invalid:聚合函数或GROUP BY子句

[英]invalid : aggregate function or the GROUP BY clause

Hey guys I can't seem to figure out what I'm doing wrong here. 嗨,我似乎无法弄清楚我在做什么错。 I'm quite new to SQL so I can't wrap my head around this. 我对SQL还是很陌生,所以我无法解决这个问题。 Any help would be great! 任何帮助将是巨大的!

SELECT PC.Name AS [ProductCategoryName]   
,      MIN(PCH.StandardCost) AS MinStandardCost
,      AVG(PCH.StandardCost) AS AverageStandardCost
,      MAX(PCH.StandardCost) AS MaxStandardCost 
FROM    ProductCategory PC
INNER JOIN    Product P ON (PC.ProductCategoryID = P.ProductCategoryID)
INNER JOIN    ProductCostHistory PCH ON ( P.ProductID = PCH.ProductID)
WHERE PC.Name LIKE '%Bike%'

You forgot the group by clause: 您忘记了group by子句:

SELECT PC.Name AS [ProductCategoryName]   
,      MIN(PCH.StandardCost) AS MinStandardCost
,      AVG(PCH.StandardCost) AS AverageStandardCost
,      MAX(PCH.StandardCost) AS MaxStandardCost 
FROM    ProductCategory PC
INNER JOIN    Product P ON (PC.ProductCategoryID = P.ProductCategoryID)
INNER JOIN    ProductCostHistory PCH ON ( P.ProductID = PCH.ProductID)
WHERE PC.Name LIKE '%Bike%'
group by PC.NAME

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在where子句中无效使用组函数且没有聚合函数 - Invalid use of group function with no aggregate function in where clause 选择列表中的'PostedVoucher.stat_flag'列无效,因为它既不包含在聚合函数中,也不包含在GROUP BY子句中 - column 'PostedVoucher.stat_flag' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause 选择列表中的 COLUMN 无效,因为它不包含在聚合函数或 GROUP BY 子句中 - Invalid COLUMN in the select list because it is not contained in either an aggregate function or the GROUP BY clause 列“Tabel1.Nama”在 select 列表中无效,因为它不包含在聚合 function 或 GROUP BY 子句中 - Column 'Tabel1.Nama' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause 在选择列表中得到错误无效,因为它不包含在聚合函数或GROUP BY子句中 - getting Error invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause 包含SQL AVG,但在选择列表中获取Column无效,因为它不包含在聚合函数或GROUP BY子句中 - Sql AVG included but getting Column is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause 无效操作:列“[column_name]”必须出现在 GROUP BY 子句中或在聚合 function 中使用; - Invalid operation: column “[column_name]” must appear in the GROUP BY clause or be used in an aggregate function; 带有Group By子句的条件聚合 - Conditional aggregate with Group By clause 必须出现在GROUP BY子句中或在聚合函数中使用(PostgreSQL) - Must appear in the GROUP BY clause or be used in an aggregate function (PostgreSQL) SQL:列必须出现在 GROUP BY 子句中或在聚合函数中使用 - SQL: Column Must Appear in the GROUP BY Clause Or Be Used in an Aggregate Function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM