Mysql select语句设置默认值

时间:2014-05-22 08:09:29   收藏:0   阅读:418

1.在没有设置默认值的情况下:

SELECT userinfo.id, user_name, role, adm_regionid, region_name , create_time
FROM userinfo
LEFT JOIN region ON userinfo.adm_regionid = region.id
结果:

bubuko.com,布布扣

设置显示默认值:

SELECT userinfo.id, user_name, role, adm_regionid, IFNULL(region_name,0) as region_name, create_time
FROM userinfo
LEFT JOIN region ON userinfo.adm_regionid = region.id
即:如果region_name一列的值为空,则显示为0,结果为:

bubuko.com,布布扣


本文为Eliot原创,转载请注明出处:http://blog.csdn.net/xyw_blog/article/details/26250331

Mysql select语句设置默认值,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!