Kodewick
学びはじめる →
ミニチャレンジ←0 / 70

数学がいちばんのクラス

#070ミニチャレンジ約 8 分

先生がクラスごとの数学をくらべたいそうです。subject が 'math' の点数だけを見て、class でグループにまとめ、平均を求めて高い順に並べてください。class と、ROUND(…, 1) にした平均を選びます。

使うテーブル
students
  • idPK
  • name
  • class
  • age
  • city
scores
  • idPK
  • student_idFK
  • subject
  • score

scores.student_id → students.id

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.class, ROUND(AVG(scores.score), 1)
FROM students
JOIN scores ON scores.student_id = students.id
-- ここにコードを書く:WHERE で数学を残し、GROUP BY students.class、そのあと AVG(scores.score) の高い順に ORDER BY
;
Ctrl + Enter でも実行できます
結果

実行するとクエリの結果が表示されます。よさそうなら提出しましょう。