SQL Functions & CASE · Question 9 · Medium

SQL Functions & CASE question 9

Table Student:
roll | name | marks
1 | Aarav | 82
2 | Diya | 67
3 | Kabir | 45
4 | Meher | 91
5 | Rohan | 30
6 | Sneha | NULL

What do the two conditional sums return?

SELECT SUM(CASE WHEN marks >= 60 THEN 1 ELSE 0 END),
       SUM(CASE WHEN marks < 60 THEN 1 ELSE 0 END)
FROM Student;
  1. 3, 3
  2. 2, 3
  3. 3, NULL
  4. 3, 2
Answer and explanation

Answer: D. 3, 2

Explanation: Marks of 82, 67 and 91 are at least 60, giving 3. Only 45 and 30 are below 60, giving 2. Sneha's NULL marks make both conditions UNKNOWN, so she adds 0 to both sums.

Previous: Table Student: roll | name | marks 1 | Aarav | 82 2 | Diya | 67 3 | Kabir | 45… · Next: Table Student: roll | name | marks 1 | Aarav | 82 2 | Diya | 67 3 | Kabir | 45…

Practise sql functions & case

Try a fresh set of sql functions & case questions with an explanation after every answer, free and without signing up: SQL Functions & CASE practice. Or sit a full placement mock test.

More sql functions & case questions

More sql practice

UNION, INTERSECT & EXCEPT · Tables, Keys & Constraints · DML & Transactions · SELECT, WHERE & ORDER BY · SQL Joins · Aggregates & GROUP BY · Subqueries & CTEs · Window Functions

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge