Skip to content

WHEN

SET @grade = 90;
SELECT
CASE
WHEN @grade >= 90 THEN 'A'
WHEN @grade >= 80 THEN 'B'
ELSE 'C'
END;
+--------------------+
| A |
+--------------------+

In the provided SQL example, a variable @grade is set to 90. Following this, a SELECT CASE statement is used. This statement checks if @grade is greater than or equal to 90 and if it’s true, it returns ‘A’. If the condition fails, the next condition checks if @grade is greater than or equal to 80. If true, it returns ‘B’. If both conditions fail, it defaults to ‘C’. The output of the executed statement is ‘A’ since the @grade (90) is greater than or equal to 90.