sql面试题目
2014-07-29 21:17
148 查看
有3个表S,C,SC
S(SNO,SNAME)代表(学号,姓名)
C(CNO,CNAME,CTEACHER)代表(课号,课名,教师)
SC(SNO,CNO,SCGRADE)代表(学号,课号,成绩)
1 找出没有选过'黎明"老师的所有学生姓名
select s.sname
from sc,s
where sc.cno in ( select distinct cno
from c
where cteacher!='黎明' ) and sc.sno=s.sno
2 列出2门以上不及格学生的姓名和平均成绩
select s.sname,t.avg_grade
from s, select sno,avg(scgrade) avg_grade
from sc
where scgrade<60
group by sno
having count(cno)>=2 ) t
where s.sno=t.sno
3 学过1号课程又学过2号课所有学生的姓名
select s.sname
from sc ,s
where sc.cno='1' and sc.sno in (select distinct sno
from sc
where sc.cno='2' ) and sc.sno=s.sno
S(SNO,SNAME)代表(学号,姓名)
C(CNO,CNAME,CTEACHER)代表(课号,课名,教师)
SC(SNO,CNO,SCGRADE)代表(学号,课号,成绩)
1 找出没有选过'黎明"老师的所有学生姓名
select s.sname
from sc,s
where sc.cno in ( select distinct cno
from c
where cteacher!='黎明' ) and sc.sno=s.sno
2 列出2门以上不及格学生的姓名和平均成绩
select s.sname,t.avg_grade
from s, select sno,avg(scgrade) avg_grade
from sc
where scgrade<60
group by sno
having count(cno)>=2 ) t
where s.sno=t.sno
3 学过1号课程又学过2号课所有学生的姓名
select s.sname
from sc ,s
where sc.cno='1' and sc.sno in (select distinct sno
from sc
where sc.cno='2' ) and sc.sno=s.sno
相关文章推荐