Kodewick
开始学 →
小挑战←→0 / 70

光荣榜

#065小挑战连接分组约 7 分钟

学校的光荣榜只放平均分 80 及以上的学生。按学生分组,算出每人所有科目 score 的平均分(空的分数不算),只留下平均分 80 及以上的人。要 name 和平均分 ROUND(…, 1) 两列。

用到的表
students
idnameclassagecity
1Amy1A12Leeds
2Ben1A13York
3Cara1B12NULL
4Dan1B14Leeds
5Eva1A12Hull
6Finn1C13NULL
7Gus1C12York
7 行
scores
idstudent_idsubjectscore
11math92
21art78
32math65
42art88
53math74
64math55
74art90
85math81
95artNULL
107math99
10 行
query.sql
SELECT students.name, ROUND(AVG(scores.score), 1)
FROM students
JOIN scores ON scores.student_id = students.id
-- 在这里写:按 students.name 分组,再用 HAVING 留下 AVG(scores.score) >= 80 的
;
Ctrl + Enter 也能运行
结果

写好了先点「运行」看看结果,没问题再点「提交」。