简体   繁体   English

Microsoft Access 2013 GROUP BY语法错误

[英]Microsoft Access 2013 GROUP BY Syntax Error

I am using Microsoft Access 2013, and I am trying to group the data stored in my Part table, by the Class it is stored in. I have got this query created: 我正在使用Microsoft Access 2013,并且尝试按存储在部件表中的类对存储在部件表中的数据进行分组。我已经创建了以下查询:

SELECT Part.PartNum, Part.Description, Part.OnHand, Part.Class, Part.Warehouse, Part.Price
FROM Part
GROUP BY Part.Class
ORDER BY Part.PartNum;

The above SQL Code gives an error with Microsoft Access: "Your query does not include the specified expression 'PartNum' as part of an aggregate function". 上面的SQL代码给出了Microsoft Access错误:“您的查询不包含指定的表达式'PartNum'作为聚合函数的一部分”。 I am not sure what I am doing wrong... Should I create an extra column for the grouping? 我不确定自己在做什么错...我应该为分组创建一个额外的列吗?

Here is what my Part table look 这是我的零件表的外观 零件表

I think you don't understand the purpose of grouping. 我认为您不了解分组的目的。 When you group something, you have to use only grouped and aggregated columns in the select statement. 在对某些内容进行分组时,您仅需在select语句中使用分组和聚合的列。 For instance, the right query could be the following: 例如,正确的查询可能是以下内容:

SELECT Part.PartNum, SUM(Part.Price)
FROM Part
GROUP BY Part.Class, Part.Description, Part.OnHand, Part.Class, Part.Warehouse
ORDER BY Part.PartNum;

However, I there's no any aggregated function in your select. 但是,我没有选择任何聚合函数。 Describe your task clearly. 清楚地描述您的任务。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM