首页 > 数据库技术 > 详细

MySQL中的if和case语句使用总结

时间:2018-09-19 01:07:42      阅读:195      评论:0      收藏:0      [点我收藏+]
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)

MySQL中的if和case语句使用总结

原文:https://www.cnblogs.com/weibanggang/p/9672271.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!