MySQL case when 用法

MySQL case when 用法如下:

CASE [col_name] WHEN [value1] THEN [result1]…ELSE [default] END

举个例子:

查询用户的性别,数据库里存储的是0和1,显示为男和女,sql如下:

select 

CASE t.gender

when 0 THEN '男'
when 1 THEN '女'
ELSE '未知'
end
as '性别' 
from sys_user t  
原文地址:https://www.cnblogs.com/haha12/p/11734056.html