CASE Expressions — Concept Check
Questions on CASE Expressions. CASE is SQL's conditional expression; simple CASE compares one value to multiple options, while searched CASE evaluates independent boolean conditions for flexible branching.
Questions in this quiz
8 questions on CASE Expressions — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.An SQL query uses a CASE expression to categorize orders based on their status. What will be the output label for a status code 'shipped'?
- AOn the Way
- BDelivered
- CProcessing
- DAwaiting Payment
2.A database query uses a searched CASE to assign salary bands. What salary band is assigned to an employee earning 85,000?
- AMid-level
- BPrincipal
- CSenior
- DJunior
3.When using a simple CASE expression, what happens if none of the WHEN conditions match and no ELSE is specified?
- ACauses an error
- BExecutes the first WHEN condition
- CReturns a default value
- DReturns NULL
4.A query sorts orders by custom status priority using CASE in ORDER BY. What priority is given to 'paid' status?
- A2
- B3
- C4
- D1
5.Which scenario is best suited for a searched CASE expression?
- AMapping a status code to a label
- BChecking if a value falls within a range
- CComparing a value to a single constant
- DChecking for NULL values
6.A query uses CASE in a GROUP BY clause to bucket order sizes. If total_amount is 1500, which bucket does it fall into?
- Amedium
- Bunknown
- Clarge
- Dsmall
7.Why might mixing data types in different THEN branches of a CASE expression cause an error?
- ACASE requires ELSE to determine type
- BCASE cannot handle NULL values
- CThe return type is set by the first THEN branch
- DSQL can only handle one data type
8.A query uses CASE for conditional aggregation. What happens if a category is not matched in any CASE condition?
- AAn error is thrown
- BThe sum is NULL
- CThe sum for that category is 0
- DThe sum includes all unmatched categories