笔试题:SQL统计各科目中各分数线人数

题目如图:

笔试题:SQL统计各科目中各分数线人数_第1张图片

第一题:

select c.Cno,c.Cname,
    count(case when s.score between 85 and 100 then 1 end) as '[100-85分]',
    count(case when s.score between 70 and 85 then 1 end) as '[85-70分]',
    count(case when s.score between 60 and 70 then 1 end) as '[70-60分]',
    count(case when s.score<60 then 1 end) as '[60分以下]' from Course c, SC s where c.Cno = s.Cno
group by c.Cno,c.Cname

第二题:

select Sno,avg(score) from SC where Sno in (
    select s.Sno
    from SC s
    where s.score<60
    group by s.Sno having count(*)>=2
) group by Sno

你可能感兴趣的:(SQL)