NULL Handling · Question 13 · Medium

NULL Handling question 13

Table Feedback:
id | student | rating
1 | Tanvi | 4
2 | Umesh | 0
3 | Varun | 5
4 | Wasim | 0
5 | Yamini | 3

A rating of 0 means the student skipped the feedback form. What does this query return?

SELECT COUNT(*), COUNT(NULLIF(rating, 0))
FROM Feedback;
  1. 5, 5
  2. 3, 3
  3. 5, 2
  4. 5, 3
Answer and explanation

Answer: D. 5, 3

Explanation: NULLIF(rating, 0) turns each 0 into NULL and leaves 4, 5 and 3 as they are. COUNT(*) counts all 5 rows, while COUNT of the expression counts only its 3 non-NULL values.

Previous: Table Staff: id | name | dept | bonus 1 | Anita | HR | 5000 2 | Bhavesh | IT |… · Next: Table Customer: id | name | mobile | email 1 | Farhan | 9810012345 | NULL 2 |…

Practise null handling

Try a fresh set of null handling questions with an explanation after every answer, free and without signing up: NULL Handling practice. Or sit a full placement mock test.

More null handling questions

More sql practice

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

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