SQL 50题


11.查询两⻔门及其以上不不及格课程的同学的学号,姓名及其平均成绩
+先把不及格的抓出来找两个以上不及格的

select Student.Sid,Sname,ssc.ave from Student,
    (select Sid,avg(score) as ave from SC group by Sid)ssc 
    where Student.Sid = ssc.Sid 
    and Student.Sid in 
        (select t.Sid from   
             (select Sid from SC where score < 60) t 
        group by t.Sid having count(t.Sid) > 2
    );

+按人学号进行分组,找出其中两个以上不及格的
--?bug

 select student.sname,avg(sc.score)  from sc,student right join ( select t.sid,count(t.sid) from (select sid,score from sc where score <60)t group by t.sid having count(*)>1)ss on student.sid = ss.sid where sc.sid = ss.sid;
posted @ 2019-08-16 18:39  prome6  阅读(101)  评论(0编辑  收藏  举报