企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
## mysql case when then else end 语法 1. 简单函数  `CASE [col_name] WHEN [value1] THEN [result1]…ELSE [default] END` 2. 搜索函数  `CASE WHEN [expr] THEN [result1]…ELSE [default] END` ![](https://img.kancloud.cn/f8/8b/f88be78da3dd1a5803f37fe0582424d3_1068x741.png) ``` SELECT Sname '姓名', CASE Ssex WHEN '男' THEN '欧巴' WHEN '女' THEN '女神' ELSE '人妖' END '性别' FROM student ``` ``` SELECT Sname '姓名', CASE WHEN Ssex = '男' THEN '欧巴' WHEN Ssex = '女' THEN '女神' ELSE '人妖' END '性别' FROM student ``` ``` UPDATE student SET Ssex = ( CASE Ssex WHEN '男' THEN '欧巴' WHEN '女' THEN '女神' ELSE '人妖' END ) ```