🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: SQL for Data Analysis: all 9 questions

Quiz: SQL for Data Analysis · Question 2 of 9

Why is COUNT(CASE WHEN x 5 THEN 1 ELSE 0 END) a bug?

Why is COUNT(CASE WHEN x > 5 THEN 1 ELSE 0 END) a bug?

  1. A.CASE cannot be used inside COUNT
  2. B.It counts only rows where x > 5
  3. C.COUNT counts the 0s as well, so it returns the number of all rows
  4. D.It returns NULL
Answer & explanation

Correct answer: COUNT counts the 0s as well, so it returns the number of all rows

COUNT skips only NULLs. Drop the ELSE, or use SUM.

Can you get the rest right without peeking?

Take the timed Quiz: SQL for Data Analysis quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →