[英]“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_stop
和Nn
分组时获得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. 查询不包括指定的表达式作为聚合函数的一部分。
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_stop
和Nn
)压缩一组记录。 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(L)
第一值- First(L)
Last(L)
最后一个值- Last(L)
Avg(L)
平均- Avg(L)
Min(L)
最小- Min(L)
Max(L)
最大- Max(L)
Sum(L)
总和- Sum(L)
Count(*)
组中的记录Count(*)
StDev(L)
or StDevP(L)
标准偏差StDev(L)
或StDevP(L)
Var(L)
or VarP(L)
方差Var(L)
或VarP(L)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.