我想在给定的关节表中选择最高值



我正在处理两个不同的表。我想连接其中的一些信息,并选择特定列中的最高值。这是我尝试使用的代码,虽然不起的作用

SELECT
result.matric_number, max(result.331), student.last_name, student.first_name, student.other_name
from result
INNER join student on result.result_id=student.StudentID
AND
student.Session = '2020/2021'

如果在select语句中使用聚合函数,则必须使用group-by。

下面的查询返回给定组的最大值(结果(,result.matric_number、student.last_name、student.first_name、student.other_name

SELECT result.matric_number, max(result.331), student.last_name, student.first_name, student.other_name 
from result INNER join student 
on result.result_id=student.StudentID AND student.Session = '2020/2021'
group by result.matric_number,  student.last_name, student.first_name, student.other_name 

如果您想要所有记录的最大值,则删除select execpt max 中的所有列

SELECT max(结果.331(从结果INNER加入学生关于result.result_id=student.StudentID AND student。会话="2020/2021">