Back to Practice
#0102
Average Ignoring NULL Scores
EasySQL15 min10 XP
Problem
Return class_id and avg_score from scores grouped by class_id. NULL scores should be ignored by AVG. Sort by class_id.
Why This Matters
SQL NULLs are a constant interview trap. AVG ignores NULL automatically, but COUNT(*) does not.
Schema
scores(class_id INTEGER, student_id INTEGER, score REAL)
Examples
Example 1
Inputclass 1 scores: 10, NULL, 20
Outputavg_score = 15
AVG(score) ignores the NULL score.
Constraints
- Return the exact structure requested.
- Handle the edge cases mentioned in the prompt.
- Prefer clear logic over clever one-liners.
CodeSQL
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Inputclass 1 scores: 10, NULL, 20
Expectedavg_score = 15
AVG(score) ignores the NULL score.
Hidden Test Categories
all null groupno nullsmultiple classes