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;

转载于:https://www.cnblogs.com/prome6/p/11365759.html

你可能感兴趣的:(SQL 50题)