mysql 查询数据为空如何设置默认值
本文介绍了mysql 查询数据为空如何设置默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
如何把查询出来的null 默认为0;
SQL是:select name,sum(score) as cou from student left join score on (student.id=score.stu_id) group by stu_id order by cou desc;
求指导
解决方案
select name,sum(if(score is null,0,score)) as cou from student left join score on (student.id=score.stu_id) group by stu_id order by cou desc;
试一下这个
这篇关于mysql 查询数据为空如何设置默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文