Which fix removes the bug?
SELECT AVG(score) FROM results; -- scores: 10, NULL, 20 -- expected 10 (a missing score counts as 0)
- Use
AVG(COALESCE(score, 0)) - Use
AVG(DISTINCT score) - Use
SUM(score) / COUNT(score) - Add
WHERE score IS NOT NULL
AVG skips NULLs, giving 15. COALESCE turns the NULL into 0 so it is counted: (10 + 0 + 20) / 3 = 10.
Play Problem Solving ▸