要求是
统计列印各科成绩,各分数段人数:课程ID,课程名称,[100-85],[85-70],[70-60],[ <60]
sc是成绩表,course是课程表
下面是语句
select sc.cid as 课程ID,course.name as 课程名称
,sum(case when score between 85 and 100 then 1 else 0 end)as [100-85]
,sum(case when score between 70 and 85 then 1 else 0 end) as [70-85]
,sum(case when score between 60 and 70 then 1 else 0 end) as [60-70]
,sum(case when score < 60 then 1 else 0 end)as [<60]
from sc,course
where sc.cid=course.cid
group by sc.cid,course.name
为什么用的是sum而不是count?