Table Exam(roll, marks) has marks 45, 50, 72, 38 and 90. SELECT SUM(CASE WHEN marks >= 50 THEN 1 ELSE 0 END) FROM Exam; What is returned?
Correct answer D. 3
Explanation
The CASE expression turns each row into 1 if marks are at least 50, and 0 otherwise. Summing those flags counts the passing rows: 50, 72 and 90, giving 3. The answer 2 forgets that >= includes 50. The answer 212 would come from summing the marks themselves. This SUM-of-CASE pattern is a portable way to do conditional counting.
Answer checked How we write and check questions
Discussion