What does the following CASE statement do? SQL: SELECT OrderID, CASE WHEN Sales > 500 THEN 'High' ELSE 'Low' END AS SalesCategory FROM Orders;

SQL CASE Statement MCQs

Quiz
•
Other
•
Professional Development
•
Hard
Dinesh Kumar
FREE Resource
15 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
10 sec • 1 pt
Classifies sales into multiple bands
Returns NULL for Sales < 500
Categorizes each order as 'High' or 'Low' based on sales
Updates Sales values
Answer explanation
The CASE statement categorizes each order based on the Sales value. If Sales is greater than 500, it labels the order as 'High'; otherwise, it labels it as 'Low'. Thus, it effectively categorizes orders into 'High' or 'Low'.
2.
MULTIPLE CHOICE QUESTION
10 sec • 1 pt
Which SQL clause can include a CASE statement?
SELECT
WHERE
ORDER BY
All of the above
Answer explanation
The CASE statement can be used in various SQL clauses, including SELECT for conditional column values, WHERE for filtering, and ORDER BY for sorting based on conditions. Therefore, the correct answer is 'All of the above'.
3.
MULTIPLE CHOICE QUESTION
10 sec • 1 pt
What does the following query return? SQL: SELECT Region, CASE WHEN AVG(Sales) > 1000 THEN 'High Sales Region' ELSE 'Low Sales Region' END AS RegionCategory FROM Orders GROUP BY Region;
Error
Categorizes regions based on total orders
Labels regions by average sales
Filters regions
Answer explanation
The query results in an error because the AVG(Sales) function is used without a proper aggregation context in the GROUP BY clause. It does not categorize regions correctly.
4.
MULTIPLE CHOICE QUESTION
10 sec • 1 pt
What is the output of this query? SQL: SELECT OrderID, CASE Profit WHEN 0 THEN 'No Profit' ELSE 'Some Profit' END AS ProfitStatus FROM Orders;
Returns error
Uses simple CASE to check Profit = 0
Categorizes into profit ranges
Complex condition evaluation
Answer explanation
The query uses a simple CASE statement to evaluate the Profit column. It checks if Profit equals 0 and returns 'No Profit'; otherwise, it returns 'Some Profit'. Thus, the correct choice is that it uses simple CASE to check Profit = 0.
5.
MULTIPLE CHOICE QUESTION
10 sec • 1 pt
Identify the type of CASE used below: SQL: SELECT OrderID, CASE WHEN Profit > 1000 THEN 'Excellent' WHEN Profit > 500 THEN 'Good' ELSE 'Average' END AS ProfitBand FROM Orders;
Simple CASE
Searched CASE
Nested CASE
Invalid syntax
Answer explanation
The SQL uses a Searched CASE because it evaluates multiple conditions (Profit > 1000, Profit > 500) rather than a single expression. This allows for more complex logic compared to a Simple CASE.
6.
MULTIPLE CHOICE QUESTION
10 sec • 1 pt
How many WHEN clauses can a CASE statement have?
Only one
Up to 2
Unlimited
Exactly 3
Answer explanation
A CASE statement can have an unlimited number of WHEN clauses, allowing for multiple conditions to be evaluated. This flexibility makes it a powerful tool for conditional logic in SQL.
7.
MULTIPLE CHOICE QUESTION
10 sec • 1 pt
What does this query do? SQL: SELECT CustomerID, CASE WHEN EXISTS ( SELECT 1 FROM Returns WHERE Returns.CustomerID = Orders.CustomerID ) THEN 'Returned' ELSE 'Not Returned' END AS ReturnStatus FROM Orders;
Error due to EXISTS
Uses correlated subquery inside CASE
Uses HAVING clause
Filters only returned orders
Answer explanation
The query uses a correlated subquery within the CASE statement to check if a customer has any returns. It assigns 'Returned' or 'Not Returned' based on the existence of records in the Returns table for each CustomerID.
Create a free account and access millions of resources
Similar Resources on Wayground
10 questions
Zendesk Layout Workshop

Quiz
•
Professional Development
20 questions
Vocabulary - Work

Quiz
•
Professional Development
15 questions
SQL Joins MCQs

Quiz
•
Professional Development
16 questions
B2B Assessment Practice

Quiz
•
Professional Development
18 questions
General Question - Disclosure SSE Framework Circular

Quiz
•
Professional Development
11 questions
General Orders

Quiz
•
Professional Development
10 questions
Команда Select

Quiz
•
Professional Development
11 questions
11 General orders!

Quiz
•
Professional Development
Popular Resources on Wayground
25 questions
Equations of Circles

Quiz
•
10th - 11th Grade
30 questions
Week 5 Memory Builder 1 (Multiplication and Division Facts)

Quiz
•
9th Grade
33 questions
Unit 3 Summative - Summer School: Immune System

Quiz
•
10th Grade
10 questions
Writing and Identifying Ratios Practice

Quiz
•
5th - 6th Grade
36 questions
Prime and Composite Numbers

Quiz
•
5th Grade
14 questions
Exterior and Interior angles of Polygons

Quiz
•
8th Grade
37 questions
Camp Re-cap Week 1 (no regression)

Quiz
•
9th - 12th Grade
46 questions
Biology Semester 1 Review

Quiz
•
10th Grade