CASE

A logical test that creates different output based on the conditions of each CASE statement, closes with an END clause.

Code Example

SELECT student_name AS 'Student',
overall_gpa AS 'GPA',
CASE
WHEN overall_gpa > 3.0 THEN "Exceptional grades, keep up the good work!"
WHEN overall_gpa BETWEEN 2.0 AND 3.0 THEN "Good job! Study hard this term!"
ELSE "You're at risk of academic probation, seek help if needed."
END
FROM students;
Interested in helping build Docs? Read the Contribution Guide or share your feedback.

Learn SQL on Codecademy