select Sname from S,P,S_P where s.sno=s_p.sno and s_p.pno=p.pno and p.level='国家级' groupby s.sno havingcount(*)>=2; -- (2)查询计算机学院没有参与过任何项目的学生学号和姓名;
select s.sno,sname from s,d where s.dno=d.dno and d.dname='计算机学院'and s.sno notin( selectdistinct sno from s_p ) -- (3)查询参与了王平负责的所有项目的学生姓名和联系方式;
王平负责的所有项目 --> 小集合B
s_p --> 大集合A xxx参与的项目
不存在B-A
A:
select pno from s_p where sno='xxx'
B: select pno from p,s where p.sno=s.sno and s.sname='王平'
select sno,sname from s as a notexists( (select pno from p,s as b where p.sno=b.sno and b.sname='王平') except( select pno from s_p where s_p.sno=a.sno ) )
另一种方法
select sno,sname from s wherenotexists( select* from p,s as b where p.sno=b.sno and b.sname='王平'andnotexists( select* from s_p where p.pno=s_p.pno ans s_p.sno=s.sno; ) ); -- (4)对 2017年立项的项目,统计各学院立项项目的平均资助金额;
select d.dno,d.dname,avg(Funding) from d,p where d.dno=p.dno and p.year=2017 groupby d.dno;