SQL 练习19

  • 统计各科成绩各分数段人数:课程编号,课程名称,[100-85],[85-70],[70-60],[60-0]
SELECT Course.CId,Course.Cname ,t.[0-60],t.[60-70],t.[70-85],t.[85-100] from Course,
(
SELECT cid,
SUM(case WHEN  score<60 THEN 1 ELSE 0 END) as [0-60],
SUM(case WHEN  score>=60 AND score<70 THEN 1 ELSE 0 END) as [60-70],
SUM(case WHEN  score>=70 AND score <85 THEN 1 ELSE 0 END) as [70-85],
SUM(case WHEN  score>85 AND score<=100 THEN 1 ELSE 0 END) as [85-100]
from SC GROUP BY cid
) t WHERE Course.CId = t.cid

image

posted @ 2021-08-20 15:02  弩哥++  阅读(51)  评论(0编辑  收藏  举报