Mysql select语句设置默认值

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

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

结果:

Mysql select语句设置默认值

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveHl3X2Jsb2c=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">

设置显示默认值:

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,结果为:

Mysql select语句设置默认值

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

上一篇:总结:JavaScript异步、事件循环与消息队列、微任务与宏任务


下一篇:webService