如何把查询出来的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;
求指导
如何把查询出来的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;
求指导
综合一楼和一楼评论,应该用在sum累加score的值前,使用ifnull(expr1,0)判断score列值是否为空,为空则以0计算
select name,sum(ifnull(score,0)) as cou from student left join score on (student.id=score.stu_id) group by stu_id order by cou desc;
2 回答7.5k 阅读✓ 已解决
2 回答6.7k 阅读✓ 已解决
1 回答5.3k 阅读✓ 已解决
1 回答5k 阅读✓ 已解决
5 回答631 阅读✓ 已解决
1 回答4.3k 阅读
3 回答773 阅读✓ 已解决
试一下这个