create table test( id int primary key auto_increment, name varchar(20), sex int ) insert into test(name,sex) values(‘小明‘,1),(‘小兰‘,0),(‘小邹‘,1),(‘小孟‘,0) select id ,name ,if(sex=1,‘男‘,‘女‘) from test select id ,name ,case sex when 1 then ‘男‘ else ‘女‘ end as sex from test
if([字段名]=[条件],[为真时返回],[为假时返回])
case [字段名] when [条件] then [为真时返回] else [为假时返回] end as sex from test
case [字段名] when [条件] then [为真时返回] end as sex from test (该语句为假时候返回null)
原文地址:https://www.cnblogs.com/weibanggang/p/9672271.html
时间: 2024-10-31 08:55:20