学生数据库查询两门及以上不及格课程的学生姓名及其平均成绩
学生数据库查询两门及以上不及格课程的学生姓名及其平均成绩
s_01表: (sno,sname)
sc_01表:(sno,cno,scgrade)
答案是这样的:
select s_01.sname,avg(sc_01.scgrade)
from s_01,sc_01 where s_01.sno=sc_01.sno
and
(select count(*) from sc_01 where s_01.sno=sc_01.sno and sc_01.scgrade<60)>=2
group by s_01.sname;
没有搞懂它的子查询的结果是什么,另外子查询中用了s_01表,为什么不用在子查询的where中写出来?
下面是我自己些的查询,效果和上面一样,有什么区别吗
select s_01.sname,avg(sc_01.scgrade)
from s_01,sc_01
where s_01.sno=sc_01.sno
and s_01.sno in
(select sc_01.sno from sc_01 where sc_01.scgrade<60 group by sc_01.sno having count(sc_01.sno)>=2)
group by sc_01.sno