参考链接:https://blog.csdn.net/rongtaoup/article/details/82183743
select score, (
case when t.enabled>=60 then '及格'
when t.score<60 then '不及格'
when t.score is null then '考试缺席' --如果score的值为null时
else enabled end --控制如果score不是数字并且null值时输出原数据
) as 成绩等级 from student t
注意:
- THEN后边的值与ELSE后边的值类型应一致,否则会报错
- 判断数据为null的写法
CASE WHEN score IS NULL THEN '缺席考试' ELSE '正常' END