Skip
Arish's avatar

140. Conditional CASE Expression


CASE Expression

sql
1SELECT name, marks,
2  CASE
3    WHEN marks >= 90 THEN 'Excellent'
4    WHEN marks >= 80 THEN 'Good'
5    WHEN marks >= 70 THEN 'Average'
6    ELSE 'Needs Work'
7  END AS performance
8FROM students;

Simple CASE

sql
1SELECT name,
2  CASE grade
3    WHEN 'A' THEN 'Top'
4    WHEN 'B' THEN 'Good'
5    ELSE 'Other'
6  END AS tier
7FROM students;