要选择一个非聚合函数

时间:2019-07-02 11:33:16

标签: sql ms-access

我有4张桌子:

学生:

student_id(PK)
student_name
section_ID

部分:

section_ID(PK)
section

班级:

class_ID(PK)
class
section_ID

标记:

student_id(CK)
subject_id(CK)
marks

使用以下代码

SELECT Class.Class, MAX(Marks.Marks) AS Total_Marks
FROM Marks, Class, Student, Section
WHERE Marks.Student_ID = Student.Student_ID
AND Student.Section_ID = Section.Section_ID
AND Section.Section_ID = Class.Section_ID
GROUP BY Class.Class

我能够在每个班级中找到最高分,但我也想显示学生的姓名或学生ID

请帮帮我 我正在使用MS ACCESS

1 个答案:

答案 0 :(得分:-1)

select st.student_name, max(marks)
    from student st, student_id s, section s
    where marks= (select max(marks)
    from student_id) and s.student_id = st.student_id
and st.section_id = s.section_id
group by st.student_name