首页 > 开发 > MySQL > 正文

mysql 查询数据为空如何设置默认值

2017-09-08 08:51:07  来源:网友分享


如何把查询出来的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;

试一下这个