MYSQL判断函数
判断函数
- ifnull(x , val) : 如果 x 的值 为 null , 则 取 val , 给 x 设置 默认值
- if (bool , x, y ) : 如果 bool 返回 真 ,则 取 x 否则 取 y , (等价于 三元运算符 )
- case when …
select score, case when score >= 90 then '优秀' when score >= 80 then '良好' when score >= 70 then '中等' when score >= 60 then '及格' else '不及格' end as level from student ; select score, case floor(score / 10) when 9 then '优秀' when 8 then '良好' when 7 then '中等' when 6 then '及格' else '不及格' end as level from student ;