SQL Functions & CASE · Question 20 · Hard
SQL Functions & CASE question 20
Table Student:
roll | name | marks
1 | Aarav | 82
2 | Diya | 67
3 | Kabir | 45
4 | Meher | 91
5 | Rohan | 30
6 | Sneha | NULL
Each student is placed in a band and the bands are counted. What does this query return?
SELECT band, COUNT(*)
FROM (SELECT CASE WHEN marks >= 80 THEN 'High'
WHEN marks >= 50 THEN 'Mid'
ELSE 'Low' END AS band
FROM Student) t
GROUP BY band
ORDER BY band;
- High, 2; Low, 2; Mid, 1
- High, 2; Low, 3; Mid, 1
- High, 2; Low, 2; Mid, 2
- High, 2; Low, 2; Mid, 1; NULL, 1
Answer and explanation
Answer: B. High, 2; Low, 3; Mid, 1
Explanation: Marks 82 and 91 give High and 67 gives Mid. 45 and 30 fall to the ELSE, and so does Sneha: her NULL marks make both WHEN tests UNKNOWN, so she is also labelled Low. That makes Low 3.
Previous: 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
- Table Payment: id | mode | amount | status 1 | UPI | 500 | SUCCESS 2 | CARD |…
- Table Payment: id | mode | amount | status 1 | UPI | 500 | SUCCESS 2 | CARD |…
- Table Student: roll | name | marks 1 | Aarav | 82 2 | Diya | 67 3 | Kabir | 45…
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