数据库笔试题
筆試題一
? ? ? ? 1:已知關系模式:
? ? ? ? ? ? ?S(SNO, SNAME)學生關系,SNO為學號,SNAME為姓名;
? ? ? ? ? ? ?C(CNO, CNAME, CTEACHER)課程關系,CNO為課程號,CNAME為課程名,CTEACHER為任課教師? ? ? ? ? ? ?SC(SNO, CNO, SCGRADE)選課關系,SCGRADE為成績
? ? ? ? ?a:書寫SQL,找出沒有選修過‘李明’老師講授課程的所有學生姓名:
方法一:
select sname from s where sno in (select distinct sno from c, sc where c.cno = sc.cno and cteacher != '李明' and sc.sno = s.sno );方法二: select sname from s where not exists(select * from sc, c where sc.cno = c.cno and c.cteacher = '李明' and sc.sno = s.sno )? ? ? ? ?b:書寫SQL,列出有兩門以上(含兩門)不及格課程的學生姓名及其平均成績:
select s.sname, avg_scgrade(sc.scgrade) from s, sc (select sno from sc where scgrade < 60 order by sno having count(distince cno) >= 2) a where s.sno = a.sno and sc.sno = a.sno group by s.sname;? ? ? ? ?c:書寫SQL,列出既學過‘1’號課程,又學過‘2’號課程的所有學生姓名:
select s.sname from s, (select sc.sno from sc, c where sc.cno and c.cno and c.cname in ('1', '2') group by sno having count(distinct cno) = 2 ) sc where s.sno = sc.sno;? ? ? ? ?d:書寫SQL,列出‘1’號課程成績比‘2’號同學該門課成績高的所有學生的學號:
select s.sname from s, sc sc1, sc sc2 where sc1.sno = '1' and sc2.sno = '2' and sc1.cno = s.cno and sc1.scgrade > sc2.scgrade? ? ? ? ?e:列出‘1’號課成績比‘2’號課成績高的所有學生的學號及其‘1’號課和‘2’號課的成績:
select sc1.sno, sc1.scgrade 1號課成績, sc2.scgrade 2號課成績 from sc sc1, sc sc2where sc1.cno = '1' and sc2.cno = '2' and sc1.sno = sc2.sno and sc1.scgrade > sc2.scgrade總結
- 上一篇: Linux快捷键列表
- 下一篇: IIC驱动5150遇到麻烦