Kodewick
Empieza a aprender →
Mini reto←0 / 70

La mejor clase en mates

#070Mini reto8 min

La profesora quiere comparar las clases en mates. Mira solo las notas cuyo subject es 'math', agrupa por class, calcula la media y ordena de mayor a menor. Elige class y la media con ROUND(…, 1).

Las tablas
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 filas
scores
idstudent_idsubjectscore
11math92
21art78
32math65
42art88
53math74
64math55
74art90
85math81
95artNULL
107math99
10 filas
query.sql
SELECT students.class, ROUND(AVG(scores.score), 1)
FROM students
JOIN scores ON scores.student_id = students.id
-- tu código aquí: WHERE para quedarte con math, GROUP BY students.class y luego ORDER BY AVG(scores.score) de mayor a menor
;
Ctrl + Enter también ejecuta
Resultado

Ejecutar muestra lo que da tu consulta. Cuando se vea bien, Enviar.