🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 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 ) ```