Mysql select语句设置默认值的方法
时间:2021-05-13 08:14:07|栏目:Mysql|点击: 次
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
上一篇:mysql自动停止 Plugin FEDERATED is disabled 的完美解决方法
栏 目:Mysql
下一篇:深入char、varchar、text和nchar、nvarchar、ntext的区别详解
本文地址:http://www.codeinn.net/misctech/120633.html