Skip to content
RED SAGSkills

Average Score per Subject

exam_results holds one row per student per subject. A NULL score means the student was absent; absences must not count toward the average.

For each subject, compute the average score rounded with ROUND(x, 2). A subject where every score is NULL should still appear with a NULL average.

Return columns subject, avg_score. Order by avg_score descending, then subject ascending (in SQLite NULLs sort last when descending).

Schema

CREATE TABLE exam_results (
  student_id INTEGER NOT NULL,
  subject TEXT NOT NULL,
  score INTEGER
);

Sample data

exam_results

student_idsubjectscore
1Math78
2Math91
3MathNULL
1Physics66
2Physics74
3Physics81
1English88
2English85
Hint 1

AVG ignores NULL values, which is exactly the behaviour you want for absences.

Hint 2

Round inside the SELECT and sort by the alias.

Good practice for: Data Analyst, Data Scientist, Business Analyst

SQL (SQLite)

Run checks your query on the sample data (Ctrl + '). Submit also checks hidden databases.