SQL 练习19
阅读原文时间:2023年07月08日阅读:1
  • 统计各科成绩各分数段人数:课程编号,课程名称,[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