我有以下三个表:
student
-------
stnumb
stname
gender
grade
born
subject
-------
subjnumb
subjname
tname
results
-------
stnumb
subjnumb
percent
我需要退回highest result and its subject for each student
示例:鲍勃·史密斯,IPT,92
我得到的两个最接近的结果是:
SELECT stname
, subjname
, highestmark
FROM (
SELECT MAX(results.percent) as "highestmark"
, student.stname
, subject.subjname
FROM student
, subject
, results
WHERE results.stnumb = student.stnumb
AND results.subjnumb = subject.subjnumb
GROUP BY stname
) maxresult
...和...
SELECT student.stname as Student
, subject.subjname as Subject
, results.percent as Mark
FROM results
JOIN student
ON results.stnumb = student.stnumb
JOIN subject
ON results.subjnumb = subject.subjnumb
ORDER BY stname
有人可以指出我正确的方向吗?我已经为此工作了好几天,但没有取得任何进展。