Bird
0
0

Given a table Employees with columns Salary and Department, what will this query return?

medium📝 query result Q4 of 15
SQL - CASE Expressions
Given a table Employees with columns Salary and Department, what will this query return?
SELECT Name, CASE WHEN Department = 'Sales' THEN CASE WHEN Salary > 5000 THEN 'High' ELSE 'Low' END ELSE 'Other' END AS SalaryLevel FROM Employees;
AReturns only employees from Sales department
BLabels 'High' or 'Low' for all employees regardless of department
CLabels 'High' or 'Low' for Sales dept salaries, 'Other' for others
DReturns salary amounts instead of labels
Step-by-Step Solution
Solution:
  1. Step 1: Analyze outer CASE

    If Department is 'Sales', inner CASE runs; else returns 'Other'.
  2. Step 2: Analyze inner CASE

    For Sales, if Salary > 5000 then 'High', else 'Low'. Others get 'Other'.
  3. Final Answer:

    Labels 'High' or 'Low' for Sales dept salaries, 'Other' for others -> Option C
  4. Quick Check:

    Nested CASE outputs labels by dept and salary [OK]
Quick Trick: Outer CASE filters department, inner CASE checks salary [OK]
Common Mistakes:
  • Assuming all employees get High/Low
  • Filtering rows instead of labeling
  • Returning salary numbers instead of labels

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes