0
0
SQLquery~5 mins

CASE in SELECT for computed columns in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the CASE statement do in a SELECT query?
It allows you to create new columns with values that depend on conditions, like an IF-THEN-ELSE in your query.
Click to reveal answer
beginner
Write a simple CASE expression to show 'Adult' if age >= 18, else 'Minor'.
CASE WHEN age >= 18 THEN 'Adult' ELSE 'Minor' END
Click to reveal answer
intermediate
Can CASE be used to create multiple computed columns in one SELECT?
Yes, you can use multiple CASE expressions in the same SELECT to create several computed columns.
Click to reveal answer
intermediate
What happens if no WHEN condition matches and there is no ELSE in CASE?
The CASE expression returns NULL for that row.
Click to reveal answer
beginner
Why use CASE in SELECT instead of filtering rows with WHERE?
CASE lets you keep all rows but change or add column values based on conditions, while WHERE filters out rows.
Click to reveal answer
What keyword starts a conditional expression inside SELECT to create computed columns?
ACASE
BIF
CWHEN
DSELECT
What does ELSE do in a CASE expression?
ASpecifies the default value if no WHEN matches
BEnds the CASE expression
CStarts a new condition
DFilters rows
If you want to label ages >= 65 as 'Senior', which WHEN clause is correct?
AWHEN age <= 65 THEN 'Senior'
BWHEN age < 65 THEN 'Senior'
CWHEN age = 65 THEN 'Senior'
DWHEN age >= 65 THEN 'Senior'
What will this CASE return if age = 20? CASE WHEN age < 18 THEN 'Child' ELSE 'Adult' END
A'Child'
B'Adult'
CNULL
DError
Can CASE expressions be nested inside each other in SELECT?
AOnly in WHERE clause
BNo
CYes
DOnly in UPDATE statements
Explain how to use CASE in a SELECT statement to create a new column based on conditions.
Think of CASE as an IF-THEN-ELSE inside your query.
You got /5 concepts.
    Describe what happens if no WHEN condition matches and there is no ELSE clause in a CASE expression.
    What does SQL do when no condition fits and no default is given?
    You got /3 concepts.