category for a row where sales_amount is 150?SELECT
sales_amount,
CASE
WHEN sales_amount > 200 THEN 'High'
WHEN sales_amount > 100 THEN 'Medium'
ELSE 'Low'
END AS category
FROM sales_dataThe CASE statement checks conditions in order. Since 150 is not greater than 200, the first WHEN is false. The second WHEN checks if 150 is greater than 100, which is true, so the category is 'Medium'.
status = 'Active'?SELECT
user_id,
CASE
WHEN last_login > CURRENT_DATE - INTERVAL '30 days' THEN 'Active'
ELSE 'Inactive'
END AS status
FROM user_loginsThe CASE checks if last_login is within the last 30 days. Those users get 'Active'. Others get 'Inactive'. So only users with recent logins are 'Active'.
score. What error will it raise?SELECT
user_id,
CASE
WHEN score > 90 THEN 'Excellent'
WHEN score > 75 THEN 'Good'
ELSE 'Average'
END AS performance
FROM user_scores
WHERE score >= 0The CASE statement is correctly formed with END. The WHERE clause filters out negative scores but does not exclude NULLs, which may or may not cause issues depending on the database. However, no syntax or type errors exist here.
risk_level in your dbt model based on credit_score: scores above 700 are 'Low', between 500 and 700 are 'Medium', and below 500 are 'High'. Which SQL snippet correctly implements this?Option A correctly assigns 'Low' for scores strictly greater than 700, 'Medium' for scores from 500 up to and including 700, and 'High' otherwise. This matches the requirement.
Nested CASE statements let you build multi-level decisions, like if/else inside if/else, while multiple WHENs in one CASE are checked sequentially in a flat structure.