MS Access 和计算列平均值的问题

发布于 2024-11-08 20:18:43 字数 675 浏览 0 评论 0原文

我有这个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

峩卟喜欢 2024-11-15 20:18:43

此查询是否表达了您要查找的平均值?

SELECT studentId, Avg(grade) AS average_grade
FROM [Student-Topic]
GROUP BY studentId;

如果是这样,您可以将其保存为单独的查询并将其与原始查询连接起来。或者将其作为子查询包含在原始查询中。

编辑:哎呀。子查询可能会出现问题,因为表名必须用括号括起来……当 Access 的查询设计器在子查询周围使用方括号时,这可能会使 Access 的查询设计器感到困惑。最好为表指定一个不需要括号的名称... Student_Topic 而不是 Student-Topic。

Does this query express the averages you're looking for?

SELECT studentId, Avg(grade) AS average_grade
FROM [Student-Topic]
GROUP BY studentId;

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.

萌逼全场 2024-11-15 20:18:43

使用聚合函数时必须对数据进行分组。

  • 即添加一个 GROUP BY 子句。

you must group your data when using aggregate functions.

  • i.e. add a GROUP BY clause.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文