如何把查询出来的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;
3 回答1.7k 阅读✓ 已解决
2 回答1.2k 阅读✓ 已解决
2 回答1.4k 阅读✓ 已解决
3 回答1.1k 阅读✓ 已解决
2 回答1.3k 阅读✓ 已解决
1 回答1.3k 阅读✓ 已解决
1 回答1k 阅读✓ 已解决
试一下这个