我有以下MS-Access SQL表: -
NAME,SUBJECT,SCORE
..我需要找到平均分数,最高分和最高分数的主题。我设法生成以下查询但不确定如何合并SUBJECT字段: -
SELECT NAME, Avg(SCORE) AS AverageScore, MAX(SCORE) AS best_score
FROM Scoretable
GROUP BY NAME
有什么想法吗?
答案 0 :(得分:2)
select sm.NAME, sm.AverageScore, sm.best_score, s.SUBJECT
from (
SELECT NAME, Avg(SCORE) AS AverageScore, MAX(SCORE) AS best_score
FROM Scoretable
GROUP BY NAME
) sm
inner join Scoretable s on sm.NAME = s.NAME
and sm.best_score = s.SCORE