1. Home
  2. Data Science
  3. SQL for Data Analysis
  4. What is AVG(col) over the three values 10, 20 and NULL?

Added 30 Nov -0001

What is AVG(col) over the three values 10, 20 and NULL?

  1. 20, because the median of the three values is used instead of the mean
  2. NULL, because any NULL in the input makes the aggregate NULL
  3. 15, because the NULL is excluded from both the sum and the count Correct answer
  4. 10, because the NULL is treated as a zero value in the average

Correct answer

C. 15, because the NULL is excluded from both the sum and the count

15 views

MCQSEXAM

Explanation

Aggregate NULL handling: most aggregates ignore NULL inputs, so AVG computes 30 divided by 2 and returns 15 rather than 10. Treating NULL as zero would be AVG(COALESCE(col, 0)) = 10, a different and often wrong question. SUM over only NULLs returns NULL, while COUNT returns 0.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More SQL for Data Analysis MCQs

Practise all SQL for Data Analysis MCQs

Similar MCQs