Mysql select语句设置默认值的方法
程序员文章站
2024-02-29 20:07:40
1.在没有设置默认值的情况下: 复制代码 代码如下:select userinfo.id, user_name, role, adm_regionid, region_na...
1.在没有设置默认值的情况下:
select userinfo.id, user_name, role, adm_regionid, region_name , create_time
from userinfo
left join region on userinfo.adm_regionid = region.id
结果:
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,结果为:
本文来自:http://blog.csdn.net/xyw_blog/article/details/26250331
复制代码 代码如下:
select userinfo.id, user_name, role, adm_regionid, region_name , create_time
from userinfo
left join region on userinfo.adm_regionid = region.id
结果:
设置显示默认值:
复制代码 代码如下:
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,结果为:
本文来自:http://blog.csdn.net/xyw_blog/article/details/26250331