← 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?
- A.CASE cannot be used inside COUNT
- B.It counts only rows where x > 5
- C.COUNT counts the 0s as well, so it returns the number of all rows
- 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 →