mysql case when 理解和应用

时间:2020-08-04 09:54:24   收藏:0   阅读:83

简单函数
CASE [col_name] WHEN [value1] THEN [result1]…ELSE [default] END new_col_name

-- 枚举
select
t_name,
case t_name
when ‘张三‘
then ‘严肃‘
when ‘李四‘
then ‘凶狠‘
when ‘王五‘
then ‘和蔼‘
end t_character
from `teacher`

搜索函数
CASE WHEN [expr] THEN [result1]…ELSE [default] END new_col_name

-- 搜索判断
select
*,
case 
when s_score < 60 
then ‘不及格‘
when s_score >= 60 and s_score < 80
then ‘中等‘
when s_score >= 80 
then ‘优秀‘
end score_type
from `score`

 

评论(0)
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!