SQL Functions & CASE questions and answers
CASE WHEN, conditional aggregation, string and numeric functions. Practise sql functions & case questions from the sql section of placement tests, with a worked explanation after every answer. Practice is free and needs no sign-up.
Sample sql functions & case questions with worked answers
Question 1
A CASE expression has no ELSE part, and for some row none of its WHEN conditions is true. What does CASE return for that row?
- NULL
- 0
- An empty string
- An error is raised and the query stops
Answer: A. NULL
Explanation: A missing ELSE behaves like ELSE NULL. The row is still returned, with NULL in that column.
Question 2
Which statement about the SQL CASE expression is correct?
- It can be written only in the SELECT list
- It produces a value, so it can be used in SELECT, WHERE, ORDER BY and inside aggregate functions
- Every CASE must have an ELSE part, or the query does not run
- All WHEN conditions are evaluated and the last true one decides the result
Answer: B. It produces a value, so it can be used in SELECT, WHERE, ORDER BY and inside aggregate functions
Explanation: CASE is an expression, so it is allowed wherever a value is allowed. ELSE is optional (it defaults to NULL), and the first true WHEN decides the result, not the last.
Question 3
Table Student:
roll | name | marks
1 | Aarav | 82
2 | Diya | 67
3 | Kabir | 45
4 | Meher | 91
5 | Rohan | 30
6 | Sneha | NULL
This query uses the simple form of CASE (CASE marks WHEN ...). What does it return?
SELECT name,
CASE marks WHEN NULL THEN 'Absent' ELSE 'Present' END
FROM Student
WHERE roll = 6;
- Sneha, Absent
- Sneha, NULL
- No rows
- Sneha, Present
Answer: D. Sneha, Present
Explanation: CASE marks WHEN NULL compares with an equals test, marks = NULL, which is UNKNOWN even when marks is NULL. The branch never matches, so ELSE gives Present. To catch NULL, write CASE WHEN marks IS NULL THEN ...
All 20 sql functions & case questions with answers
- Table Student: roll | name | marks 1 | Aarav | 82 2 | Diya | 67 3 | Kabir | 45…
- Table Student: roll | name | marks 1 | Aarav | 82 2 | Diya | 67 3 | Kabir | 45…
- A CASE expression has no ELSE part, and for some row none of its WHEN…
- Table Student: roll | name | marks 1 | Aarav | 82 2 | Diya | 67 3 | Kabir | 45…
- The string literal below has two spaces before Pune and two spaces after it…
- Which standard SQL function converts a value from one data type to another…
- What does this query return?
- Table Student: roll | name | marks 1 | Aarav | 82 2 | Diya | 67 3 | Kabir | 45…
- Table Student: roll | name | marks 1 | Aarav | 82 2 | Diya | 67 3 | Kabir | 45…
- Table Student: roll | name | marks 1 | Aarav | 82 2 | Diya | 67 3 | Kabir | 45…
- 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 Visitor: id | city 1 | pune 2 | Delhi 3 | PUNE 4 | delhi 5 | Pune City…
- Table Salary: emp | basic | bonus Nikhil | 30000 | 5000 Ojas | 40000 | NULL…
- Which statement about the SQL CASE expression is correct?
- Table Student: roll | name | marks 1 | Aarav | 82 2 | Diya | 67 3 | Kabir | 45…
- 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…
- Table Student: roll | name | marks 1 | Aarav | 82 2 | Diya | 67 3 | Kabir | 45…
SQL Functions & CASE: common questions
What are sql functions & case questions?
CASE WHEN, conditional aggregation, string and numeric functions. They appear in the sql section of many placement tests.
Where can I practise sql functions & case questions with answers for free?
Right here on LogicWiz Exams. Every sql functions & case question has a worked explanation after you answer. Practice is free and needs no sign-up.
How should I practise sql functions & case?
Start with easy questions, then move to medium and hard. Read the explanation after each answer, and come back to the ones you missed.
Start practising
On this page you can start a fresh set of sql functions & case questions, choose easy, medium or hard, and time yourself if you want to. Or practise the whole subject: SQL practice.
More sql topics
- SELECT, WHERE & ORDER BY: Filtering, DISTINCT, IN, BETWEEN, LIKE, sorting and LIMIT.
- SQL Joins: Inner, left, right, full, cross and self joins, and row counts.
- Aggregates & GROUP BY: COUNT, SUM, AVG, grouping and HAVING versus WHERE.
- Subqueries & CTEs: Scalar and correlated subqueries, IN, EXISTS and WITH.
- Window Functions: ROW_NUMBER, RANK, DENSE_RANK, PARTITION BY, LAG and running totals.
- NULL Handling: Three-valued logic, IS NULL, COALESCE and NULL in aggregates.
- UNION, INTERSECT & EXCEPT: Combining results, duplicates and column rules.
- Tables, Keys & Constraints: CREATE, ALTER, primary and foreign keys, UNIQUE and CHECK.
- DML & Transactions: INSERT, UPDATE, DELETE, COMMIT, ROLLBACK and ACID.
Other subjects
- Quantitative Aptitude: Arithmetic, percentages, time and work, speed, probability and data interpretation: the numerical section of every fresher test.
- Logical Reasoning: Series, coding-decoding, arrangements, syllogisms and puzzles: the section that separates prepared candidates from the rest.
- Verbal Ability: Vocabulary, grammar, reading comprehension and sentence order: tested in nearly every IT services hiring exam.
- Technical & Programming: CS fundamentals, output prediction and pseudo-code: the technical MCQ round for IT roles.
- Python: Python quizzes by topic, from types and strings to classes and generators: output prediction and interview concepts.
LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge · Test from a job description · LogicWiz Open: free team quiz · Free interview prep