表结构:
S(SNO,SNAME) 代表 学号。学生姓名;
C(CNO,CNAME,CTEACHER) 代表 课号,课程名称。授课老师
SC(SNO,CNO,SCGRADE) 代表 学号。课号。课程成绩
1 查询没选过“黎明”老师的全部学生姓名。
select s.sname from s join sc on sc.sno=s.sno join c on c.cno=s.cno where c.cteacher<>'黎明'
select s.sname,c.a_grade from (select a.sno,count(cno) from (select sno,cno from sc where sc.scgrade<60) group by a.sno having count(cno)>1)b join s on b.sno=s.sno join (select avg(scgrade) a_grade,sno from sc group by sno)c on c.sno=s.sno
select s.sname from s join (select count(*),sno from (select * from sc where sc.cno in(1,2)) grout by sno having cout(*)>1)a on a.sno=s.sno
原文:http://www.cnblogs.com/clnchanpin/p/7143294.html