ACCESS 中的 GROUP BY CLAUSE 问题
我需要你帮助访问数据库
我
ID CLASS LESSON
1 7 MATH
2 7 CHEM
3 8 GEOM
4 8 MATH
5 8 CHEM
6 9 MATH
...
在 mysql 中有一个像这样的表 sql 命令
select CLASS, LESSON
from t_class
group by LESSON
会返回类似的结果,
ID CLASS LESSON
1 7 MATH
2 7 CHEM
3 8 GEOM
...
但是访问这样的 sql 命令
select CLASS, LESSON
from t_class
group by LESSON
会出现错误
您尝试执行的查询不包含指定表达式“LESSON”作为聚合函数的一部分
那么问题是什么以及如何解决问题..
谢谢
i need your help in access db
i have a table like this
ID CLASS LESSON
1 7 MATH
2 7 CHEM
3 8 GEOM
4 8 MATH
5 8 CHEM
6 9 MATH
...
in mysql sql command like this
select CLASS, LESSON
from t_class
group by LESSON
returns result like
ID CLASS LESSON
1 7 MATH
2 7 CHEM
3 8 GEOM
...
but access sql command like this
select CLASS, LESSON
from t_class
group by LESSON
gives error
You tried to execute a query that does not include the specified expression 'LESSON' as part of an aggregate function
So what is the problem and how to solve the problem..
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题是,您需要在聚合函数中指定
CLASS
,例如sum
、max
、min
、avg
或类似的。你可以尝试:
你也可以这样做
,但这有什么意义呢?
The problem is, that you need to specify
CLASS
in an aggregate function, likesum
,max
,min
,avg
or the likes.You could try:
You could also do
but what's the point there?
这会产生错误,因为如果您使用聚合函数,您只能获取经过 GROUP BY 编辑的字段以及聚合函数的结果。
它还不清楚您想要获得什么 CLASS 值?最小的可能值?然后使用聚合函数
MIN
,例如:This gives an error because if you use aggregate functions you can only get fields you
GROUP BY
-ed for, and the result of aggregate functions.It also not clear what value of CLASS you want to get? The least possible value? Then use an aggregate function
MIN
like:您需要在 LESSON 或 CLASS 上使用聚合函数(根据您的要求),因为您正在使用 GROUP BY
you need to use Aggregate function on LESSON or CLASS (as per your requirement), since you're using GROUP BY