Bird
0
0

What will be the output of this query?

medium📝 query result Q5 of 15
SQL - CASE Expressions
What will be the output of this query?
SELECT name, CASE WHEN score >= 90 THEN 'A' WHEN score >= 80 THEN 'B' ELSE 'C' END AS grade FROM students;
AOnly students with grade A
BNames with grades A, B, or C based on score ranges
CAn error due to missing ELSE clause
DGrades assigned randomly
Step-by-Step Solution
Solution:
  1. Step 1: Understand multiple WHEN conditions

    The CASE checks score ranges: ≥90 = 'A', ≥80 = 'B', else 'C'.
  2. Step 2: Output includes all students with assigned grades

    All rows show name and grade based on score, no filtering or errors.
  3. Final Answer:

    Names with grades A, B, or C based on score ranges -> Option B
  4. Quick Check:

    CASE supports multiple WHEN for ranges [OK]
Quick Trick: Use multiple WHEN for ranges in CASE [OK]
Common Mistakes:
  • Expecting filtering instead of labeling
  • Missing ELSE causes error (false)
  • Grades assigned randomly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes