在 Access 中对列中的多行进行平均

发布于 2024-11-04 11:01:29 字数 392 浏览 1 评论 0原文

我有下表:

Table 1
Student , Exam_ID
1      1      
2      1     
3      2     
1      2     
3      3     
2      3     
3      4     
1      4  

Table 2
Exam ID, Mark
(1   , 5)
(2 ,   4)
(3  ,  4)
(4 ,   5)

每项考试都是由成对的学生解决的...我希望能够平均每对学生参加的所有考试的分数,例如:考试 2 和 4 由同一对学生参加(3,1) 我希望能够计算这两次考试的平均分数,即(4,5)=4.5 然后将这些对从最高分到最低分进行排名 谢谢

如何将名字和姓氏包含到第一个表中?

I have the following tables:

Table 1
Student , Exam_ID
1      1      
2      1     
3      2     
1      2     
3      3     
2      3     
3      4     
1      4  

Table 2
Exam ID, Mark
(1   , 5)
(2 ,   4)
(3  ,  4)
(4 ,   5)

each exam is solved by pairs of students ... i want to be able to average the mark of all exams taken by each pair of student for example : Exams 2 and 4 are taken by the same pair of students (3,1) i want to be able to average the marks for those 2 exams which are(4,5)=4.5
and then rank those pairs from highest to lowest marks
thank you

How can I include First_Name and Surname into the first table?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

故乡的云 2024-11-11 11:01:29
SELECT
    a.Student AS studentA
  , b.Student AS studentB
  , AVG(T2.Mark) AS averageMark
FROM ( T2
      INNER JOIN T1 AS a
          ON a.Exam_ID = T2.Exam_ID
     )  
      INNER JOIN T1 AS b
          ON a.Exam_ID = b.Exam_ID
          AND a.Student < b.Student
GROUP BY a.Student
       , b.Student
ORDER BY AVG(T2.Mark) DESC

或者这个:

SELECT
    a.Student AS studentA
  , b.Student AS studentB
  , AVG(T2.Mark) AS averageMark
FROM ( T1 AS a
      INNER JOIN T1 AS b
          ON a.Exam_ID = b.Exam_ID
          AND a.Student < b.Student
     )
      INNER JOIN T2
          ON a.Exam_ID = T2.Exam_ID
GROUP BY a.Student
       , b.Student
ORDER BY AVG(T2.Mark) DESC

它的工作原理在这里更明显。括号内的 JOIN 找到配对,下一个 JOIN 将配对与第二个 Marks 表关联起来。

SELECT
    a.Student AS studentA
  , b.Student AS studentB
  , AVG(T2.Mark) AS averageMark
FROM ( T2
      INNER JOIN T1 AS a
          ON a.Exam_ID = T2.Exam_ID
     )  
      INNER JOIN T1 AS b
          ON a.Exam_ID = b.Exam_ID
          AND a.Student < b.Student
GROUP BY a.Student
       , b.Student
ORDER BY AVG(T2.Mark) DESC

or this:

SELECT
    a.Student AS studentA
  , b.Student AS studentB
  , AVG(T2.Mark) AS averageMark
FROM ( T1 AS a
      INNER JOIN T1 AS b
          ON a.Exam_ID = b.Exam_ID
          AND a.Student < b.Student
     )
      INNER JOIN T2
          ON a.Exam_ID = T2.Exam_ID
GROUP BY a.Student
       , b.Student
ORDER BY AVG(T2.Mark) DESC

where it is more obvious how it works. The JOIN inside the parenthesis finds the couples and next JOIN relates the couples to the second Marks table.

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