Practice mode DBMS and SQL

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.