case when 和 like结合 进行模糊查询

like 就是模糊查询 可以转换成 识别字符串中是否含 该字符串
instr 函数返回是对应字段的位置
instr(t.str,’语文’) > 0
case when (boolean) then 1 else 0 end
when 后面需要的就是个判断

case 和 when 之间存在参数的意义
判断是否相等 set 性别字段 判断性别
case set when ‘1’ then 1 else 0 end
或是 case when set == ‘1’ then 1 else 0 end
含义 set==‘1’
若 是 score 成绩
判断成绩的层次 就需要比较了
case when score>80 then ‘优秀’ else ‘不优秀’ end
case when 可以连用
case when score>80 then ‘优’
when score>60 then ‘良’
when score<60 then ‘差’

猜你喜欢

转载自blog.csdn.net/HEshenghuxi/article/details/84661188