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_id | subject | score |
|---|---|---|
| 1 | Math | 78 |
| 2 | Math | 91 |
| 3 | Math | NULL |
| 1 | Physics | 66 |
| 2 | Physics | 74 |
| 3 | Physics | 81 |
| 1 | English | 88 |
| 2 | English | 85 |
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.