I am working on MySql Workbench, and using the following case statement which shows error.
ErrorCode: 1064 you have an error in your SQL syntax: check the manual that corresponds to your MariaDB server version for the right syntax to use near.....
select id, name, percentage,
CASE
WHEN PERCENTAGE >= 80 AND <= 100 THEN "Merit"
WHEN PERCENTAGE >= 50 AND < 79 THEN "1st Division"
WHEN PERCENTAGE >= 45 AND < 60 THEN "2nd Division"
WHEN PERCENTAGE >= 33 AND < 45 THEN "3rd Division"
WHEN PERCENTAGE < 33 THEN "Fail"
ELSE "Not Correct %"
END AS Grade
from student2;
The condition like this is not valid. The second comparison (after
AND
) also need a column:You can use the following instead:
The correct query: