case when 条件1 then 取值1 when 条件2 then 取值2 else 取值3 end
when后接条件语句,then后为字段取值(数值或字符串等都可以,但类型须一致)。
1.简单case函数
case sex when '1' then '男' when '2' then '女’ else '其他' end
2.case搜索函数
case when sex = '1' then '男' 8 when sex = '2' then '女' 9 else '其他' end