A column score holds 100, 80 and NULL. What does AVG(score) return?
Correct answer
C. 90, because the NULL row is ignored in both parts
17 views
C. 90, because the NULL row is ignored in both parts
17 views
Aggregate functions skip NULL inputs entirely, so the sum is 180 and the divisor is the two non-null rows, giving 90 rather than the 60 you would get by treating the missing score as zero. This is why AVG(score) and SUM(score)/COUNT(*) disagree when NULLs are present, since COUNT(*) includes the missing row. Use COALESCE(score, 0) first if the missing values genuinely should count as zero.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is C? Ask here and get an explanation.