Kodewick
Comece a aprender →
Mini desafio←0 / 70

A melhor turma em math

#070Mini desafio8 min

A professora quer comparar as turmas em math. Olhe só as notas cujo subject é 'math', agrupe por class, calcule a média e ordene da maior para a menor. Escolha class e a média com ROUND(…, 1).

As tabelas
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 linhas
scores
idstudent_idsubjectscore
11math92
21art78
32math65
42art88
53math74
64math55
74art90
85math81
95artNULL
107math99
10 linhas
query.sql
SELECT students.class, ROUND(AVG(scores.score), 1)
FROM students
JOIN scores ON scores.student_id = students.id
-- seu código aqui: WHERE para ficar com math, GROUP BY students.class, depois ORDER BY AVG(scores.score) do maior para o menor
;
Ctrl + Enter também executa
Resultado

Executar mostra o que sua consulta devolve. Quando parecer certo, Enviar.