これはあなたが望むものだと思います。これにより、各科目で最高のスコアを持つ学生が得られます。特定の科目が必要な場合は、WHERE SubjectID=Subjects.SubjectID
を変更できます。 WHERE SubjectID=particular_subject_id
へ
SELECT Student.FirstName, Subjects.SubjectName, Grade.Grade, Subjects.SubjectID FROM
Student INNER JOIN Grade ON Grade.StudentID=Student.StudentID
INNER JOIN Subjects ON Grade.SubjectID=Subjects.SubjectID WHERE Grade.Grade=
(SELECT MAX(Grade) FROM Grade WHERE SubjectID=Subjects.SubjectID)
平均:
SELECT Subjects.SubjectName, AVG(Grade.Grade), Grade.ClassID, Subjects.SubjectID
FROM Grade INNER JOIN Subjects ON Grade.SubjectID=Subjects.SubjectID
GROUP BY Grade.ClassID, Grade.SubjectID;
これが動作中の