MS Access 和计算列平均值的问题
我有这个 MS Access 查询:
SELECT DISTINCT
Career.careerId, Student.studentName, Avg([Student-Topic].grade), Career.careerName
FROM
Career INNER JOIN
(
(Student INNER JOIN [Student-Topic]
ON Student.studentId = [Student-Topic].studentId)
INNER JOIN [Student-Career]
ON Student.studentId = [Student-Career].studentId)
ON Career.careerId = [Student-Career].careerId
WHERE
(((
[Student-Career].careerId)=[Career].[careerId]) AND
(([Student-Topic].studentId)=[Student].[studentId]));
没有 Avg 函数,查询工作正常,但是当我放置它时,它崩溃了......
我的错误是什么?
I have this MS Access query:
SELECT DISTINCT
Career.careerId, Student.studentName, Avg([Student-Topic].grade), Career.careerName
FROM
Career INNER JOIN
(
(Student INNER JOIN [Student-Topic]
ON Student.studentId = [Student-Topic].studentId)
INNER JOIN [Student-Career]
ON Student.studentId = [Student-Career].studentId)
ON Career.careerId = [Student-Career].careerId
WHERE
(((
[Student-Career].careerId)=[Career].[careerId]) AND
(([Student-Topic].studentId)=[Student].[studentId]));
Without the Avg function the query works fine, but when I place it, it breaks down...
What's my error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此查询是否表达了您要查找的平均值?
如果是这样,您可以将其保存为单独的查询并将其与原始查询连接起来。或者将其作为子查询包含在原始查询中。
编辑:哎呀。子查询可能会出现问题,因为表名必须用括号括起来……当 Access 的查询设计器在子查询周围使用方括号时,这可能会使 Access 的查询设计器感到困惑。最好为表指定一个不需要括号的名称... Student_Topic 而不是 Student-Topic。
Does this query express the averages you're looking for?
If so, you could save it as a separate query and JOIN it with your original query. Or include it within the original query as a subquery.
Edit: Oops. A subquery could be problematic since the table name must be bracketed ... that can confuse Access' query designer when it uses square brackets around a subquery. Better to give the table a name which doesn't require bracketing ... Student_Topic instead of Student-Topic.
使用聚合函数时必须对数据进行分组。
you must group your data when using aggregate functions.