c.km=’离散数学’)
2) select xh,xm from s where xh in (select a.xh from e a,e b where a.xh
=b.xh and a.kh in (select kh from c where km=’数据库原理’) and b.kh in (select kh from c where km=’离散数学’)
3. 查询每门课的排名,输出课程号,学号,总评成绩,排名;按课程号升序,课程相同按
排名从高到低。(提示:某个同学一门课的排名就是该门课成绩大于等于他的人数)
select x.kh,x.xh,x.zpcj,count(*) as pm from E as x,E as y
where (x.zpcj --加上学期 select x.xq,x.kh,x.xh,x.zpcj,count(*) pm from e as x,e as y where (x.zpcj 第4周(第四章:数据更新、视图、嵌入式SQL部分自学) 一、实验课: 1. 建立计算机学院总评不及格成绩学生的视图,包括学生学号、姓名、性别、手机、所选 课程和成绩。 2. 在E表中插入记录,把每个学生没学过的课程都插入到E表中,使得每个学生都选修每 门课。 insert into e(xh,xq,kh,gh) select s.xh,o.xq,o.kh,o.gh from s,o where s.xh+o.kh not in (select xh+kh from e) and o.kh+o.gh in (select kh+gh from o as x where gh<=all(select gh from o as y where x.kh=y.kh)) 3. 求年龄大于所有女同学年龄的男学生姓名和年龄。 4. 在E表中修改08305001课程的平时成绩,若成绩小于等于75分时提高5%,若成绩大于 75分时提高4%。 5. 删除没有开课的学院。 6. 查询优、良、中、及格、不及格学生人数 二、研讨课: 1. 补全下面程序段虚线框中的语句,使该程序能够正确地利用给出的数据库,逐个显示年 龄高于某个值(通过共享变量maxage给出)的学生的学号、姓名、性别、院系号,并按用户的当场要求,保持或修改这个学生的院系号(通过共享变量newdno中给出)。 void ChangeDNO() { … EXEC SQL BEGIN DECLARE SECTION; int maxage; char xh[7], xm[9], sex[3], yxh[4], newdno[4]; EXEC SQL END DECLARE SECTION; … gets(maxage); EXEC SQL DECLARE ex cursor for select xh,xm,xb,yxh from s where 2014-year(csrq)>:maxage; … EXEC SQL OPEN ex EXEC SQL fetch from ex into :xh,:xm,:xb,:yxh; while (1) { if (SQLCA.SQLSTATE ! =?00000?) break; printf(“%s,%s, %s,%s”, eno, ename, sex, yxh); printf(“UPDATE DNO? ”); scanf(“%c”, &yn); if (yn==?y? or yn=?Y?) { printf(“INPUT NEW DNO: ”); EXEC SQL UPDATE s set yxh=:newdno where current of ex scanf(“%c”, &newdno); EXEC SQL fetch from ex into :xh,:xm,:xb,:yxh; } } EXEC SQL CLOSE ex; … 2. 1)用多种方法表达查询:检索刘晓明不学的课程的课程号。 ① select kh from c where kh not in (select kh from s,e where s.xh=e.xh and xm=’ 刘晓明’) ② select kh from c except select kh from s,e where s.xh=e.xh and xm=’ 刘晓明’ ③ select c.kh from c left join (select kh from s,e where s.xh=e.xh and xm=’ 刘晓明’ ) as x on c.kn=x.kn where x.kh is null select c.kh from e join s on e.xh=s.xh and xm=’ 刘晓明’ right join c on e.kh=c.kh where e.kh is null 2)删除没有开课的学院。 delete from c where yxh not in (select yxh from c,o where c.kh=o.kh) delete from t where yxh not in (select yxh from c) delete from s where yxh not in (select yxh from c) delete from d where yxh not in (select yxh from c) 1) 视图判断实验课第一题的视图能否更新。 3. 1) 设计一个能更新的视图,要求更新后的数据满足视图定义的范围:“系统结构”还未 有总评成绩的选课视图。写出如下对视图的更新命令,并判断是否可行,如不可行请说出理由 create view st as select * from e where zpcj is null and kh in (select kn from c where km=’ 系统结构’) with check option ? 插入数据(1107, 2013-2014秋季, 08305004, 0101, null,null,null) 不能,主键重复 ? 插入数据(1107, 2012-2013冬季, 08305002,0102, null,null,null) 不能,插入的不是“系统结构” ? 将所有学生平时成绩增加10分,但不能超过100分 update st set pscj=100 where pscj>90 update st set pscj=pscj+10 where pscj<=90 第5周(第一、二章:数据管理、数据库技术、数据库体系结构、 DBMS,自学DBS) 一、实验课:抽查前四周的实验内容 二、研讨课:根据上半学期的学习情况,对学生在学习中的问题,两个班合班上习题课 三、作业:数据库中的 “3”(只针对数据库原理1) 1. 数据库发展史上的 3 个里程碑 2. 数据库界 3 个图灵奖获得者 3. 数据管理的 3 个阶段 4. 3种数据模型 5. 数据库系统 3 层体系结构 6. 数据抽象过程中的 3 个世界 7. 数据描述时的 3 层设计 8. 数据模型 3 要素 9. 3种数据模式 10. 数据库的 3 次大论战 11. 关系数据库的3种完整性约束 12. 能唯一标识关系中每一行的属性或属性组,有那3种键 13. 实体间的联系有那3种 14. 关系的3种更新 15. 文件系统的3个缺点