SQL CASE Statement MCQs

SQL CASE Statement MCQs

Professional Development

15 Qs

quiz-placeholder

Similar activities

General Orders (Marines)

General Orders (Marines)

5th Grade - Professional Development

11 Qs

SQL Subquery MCQs

SQL Subquery MCQs

Professional Development

15 Qs

11 General orders!

11 General orders!

Professional Development

11 Qs

SQL Joins MCQs

SQL Joins MCQs

Professional Development

15 Qs

March 25 - April 5 Update Validation

March 25 - April 5 Update Validation

Professional Development

12 Qs

Salesforce

Salesforce

Professional Development

20 Qs

Команда Select

Команда Select

Professional Development

10 Qs

SQL DECODE MCQs

SQL DECODE MCQs

Professional Development

15 Qs

SQL CASE Statement MCQs

SQL CASE Statement MCQs

Assessment

Quiz

Other

Professional Development

Hard

Created by

Dinesh Kumar

FREE Resource

15 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

10 sec • 1 pt

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

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

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?