SQL命令完成:按照课程进行汇总,输出课程号、平均分和选修人数。
我做出来:课程被选修的就有结果,没被选修的就没结果了
select course.cno,avg(grade) avggrade,count(course.cno) '选修该课程人数'
from course,sc
where course.cno=sc.cno
group by course.cno
如何能将未被选修的课程按要求也被查询出来呢?
------解决方案--------------------
- SQL code
select course.cno,avg(grade) avggrade,count(course.cno) '选修该课程人数'from course left join sc on course.cno=sc.cno group by course.cno
------解决方案--------------------
select
course.cno,avg(grade) avggrade,
isnull(count(course.cno),0) as '选修该课程人数'
from
course left join sc on course.cno=sc.cno
group by
course.cno