Kodewick
開始學 →
基礎←→0 / 70

數學平均分

#004基礎AVG + ROUND約 3 分鐘

老師想知道這次數學考得怎麼樣。從 scores 表裡算出 subject 是 'math' 的那些分數的平均分,用 ROUND(…, 1) 保留 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
-- 在這裡寫:只留數學的行,再用 AVG 算平均、ROUND 保留 1 位
SELECT score
FROM scores;
Ctrl + Enter 也能執行
結果

寫好了先點「執行」看看結果,沒問題再點「提交」。