1.找出 没选过“黎明” 老师的所有学生姓名
1)选择出黎明老师的课程编号
select cno from C where cteacher="黎明";
2)根据C表查询出来课程编号的结果,在SC学生选课表查出选黎明老师课程的学号
select sno from SC where cno=(select cno from C where cteacher="黎明");
3)然后依据以上结果在S表中查询
select sname from sno=(select sno from SC where cno=(select cno from C where cteacher="黎明"))
2. 列出2门以上(含2门)不及格学生姓名及平均成绩
1)查出学生的平均成绩
select sno, avg(scgrade) as avgscore form SC group by sno;
2)查询出2门及以上不及格的学生及姓名
select sno, scgrade from SC inner join S on SC.sno=S.sno where sc.scgrade<60 group by SC.sno,S.sname haveing count(*)>=2;
3)
select t1.sname, t2.avgscore from
(select sno, scgrade from SC inner join S on SC.sno=S.sno where sc.scgrade<60 group by SC.sno,S.sname haveing count(*)>=2;) t1
inner join
(select sno, avg(scgrade) as avgscore form SC group by sno) t2
on
t1.son=t2.son;
3. 即学过1号课程又学过2号课程所有学生的姓名
1) 查到选课为1的学生学号
select sno from SC where cno=1;
2)查到选课为2的学生学号
select sno from SC where cno=2;
3)
select sname from
SC join S
on
SC.sno=S.sno
where
SC.cno=1 and SC.sno in (select sno from SC where cno=2);