简体   繁体   English

查找组中的前3个值时,“查询不将指定的表达式作为聚合函数的一部分”

[英]“Query does not include the specified expression as part of an aggregate function” when looking for top 3 values in group

This is a sample of some of my data: 这是一些数据的示例:

样本数据

I am trying to get the top 3 values of L when grouping by ID_stop and Nn . 我正在尝试按ID_stopNn分组时获得L的前3个值。

I tried the following SQL: 我尝试了以下SQL:

SELECT TOP 3 Sclerometrica_equotip.ID_stop, Sclerometrica_equotip.Nn, Sclerometrica_equotip.L
FROM Sclerometrica_equotip
GROUP BY Sclerometrica_equotip.ID_stop, Sclerometrica_equotip.Nn
ORDER BY Sclerometrica_equotip.ID_stop, Sclerometrica_equotip.Nn;

but got the following error: 但出现以下错误:

Query does not include the specified expression as part of an aggregate function. 查询不包括指定的表达式作为聚合函数的一部分。

  1. I don't understand the error message. 我不明白该错误信息。 Can someone explain it to me? 有人可以向我解释吗?
  2. How can I accomplish what I am trying to do? 我该如何完成我想做的事情?

The error means that there are fields in your query which are not part of the grouping and also not aggregated together using an aggregate function. 该错误意味着查询中的某些字段不属于分组,也没有使用聚合函数聚合在一起。

When you group, you are condensing a set of records based on the grouped fields (in this case ID_stop and Nn ). 分组时,您将基于分组的字段(在本例中为ID_stopNn )压缩一组记录。 That means that when before you had 100 records, now you have 3. But from which of those 100 records should the value of L be taken? 这意味着当您有100条记录之前,现在有3条记录。但是,应该从这100条记录中的哪一条中取L的值? You either have to include L in the fields to group by, or you have to specify some operation that will act on all the values of L . 您必须在要分组的字段中包括L ,或者必须指定将对L所有值起作用的某些操作。 The possible operations you can use are: 您可以使用的可能操作是:

  • first value -- First(L) 第一值- First(L)
  • last value -- Last(L) 最后一个值- Last(L)
  • average -- Avg(L) 平均- Avg(L)
  • smallest -- Min(L) 最小- Min(L)
  • largest -- Max(L) 最大- Max(L)
  • sum -- Sum(L) 总和- Sum(L)
  • count of records in the group -- Count(*) 组中的记录Count(*)
  • the standard deviation -- StDev(L) or StDevP(L) 标准偏差StDev(L)StDevP(L)
  • variance -- Var(L) or VarP(L) 方差Var(L)VarP(L)

References 参考

暂无
暂无

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

相关问题 查询不包含指定的表达式作为UNION查询中聚合函数的一部分 - Query does not include the specified expression as part of an aggregate function in UNION query SQL-您的查询未将指定的表达式作为聚合函数的一部分 - SQL - Your query does not include the specified expression as part of an aggregate function 您的查询不包括指定的表达式“regNo”作为聚合函数的一部分 - Your query does not include the specified expression 'regNo' as part of an aggregate function 您的查询不包含指定表达式“ ID”作为聚合函数的一部分 - Your query does not include the specified expression “ID” as part of aggregate function Access Query +您的查询不包含指定的表达式“ TimeID”作为聚合函数的一部分 - Access Query + your query does not include the specified expression 'TimeID' as part of the aggregate function 我的 SQL 查询指出我的查询不包括指定的表达式作为聚合函数的一部分 - My SQL query states that my query does not include the specified expression as part of an aggregate function Access Update查询:查询不包含指定表达式作为聚合函数的一部分 - Access Update Query: Query does not include the specified expression as part of an aggregate function SQL语法:查询不包含指定的表达式X作为聚合函数的一部分 - SQL syntax : query does not include specified expression X as part of an aggregate function 尝试执行不包含指定表达式“ StaffDetails.StaffID”作为聚合函数一部分的查询 - Tried to execute a query that does not include the specified expression 'StaffDetails.StaffID' as part of an aggregate function MS-Access:您的查询不包括指定的表达式作为聚合函数的一部分 - MS-Access: your query does not include the specified expression as part of an aggregate function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM