山东大学数据库系统SQL上机实验代码test2——test8(2014最新版)

合集下载

山东大学数据库习题及答案

山东大学数据库习题及答案

⼭东⼤学数据库习题及答案⼭东⼤学数据库系统课程试卷A卷参考答案⼀、简答(每⼩题5分,共25分)1、如何理解空值(NULL),空值在参与运算时有哪些特点?答:空值null表⽰“不知道”或者“不存在”的含义。

不是指“0”,也不是“false”,也不是’’。

Null参与的关系运算和算术运算结果均为null。

评分细则:Null的含义3分,Null参与的运算特点2分2、简述事务的概念及其相关特性。

答:事物是访问并可能更新各种数据项的⼀个程序执⾏单元。

事物具有ACID四种特性。

A指原⼦性:事物的所有操作在数据库中要么全部正确反映出来,要么全部不反映。

C指⼀致性:事物的隔离执⾏保持数据库的⼀致性。

I指隔离性:尽管多个事物可以并发执⾏,但系统必须保证每⼀个事物都感觉不到系统中有其他事物在并发地执⾏。

D指持久性:⼀个事物成功完成后,它对数据库的改变必须是永久的。

评分细则:事物概念2分,事物的性质3分。

3、关系中的元组有先后顺序吗?为什么?答:没有。

关系是元组的集合,⽽集合中的元素是没有顺序的,因此关系中的元组也就没有先后顺序。

评分细则:第⼀问回答“有”,零分;第⼀问回答“没有”,2分,说明原因3分4、设关系模式R(A,B,C)上有⼀个多值依赖A B。

如果已知R的当前关系中存在着三个元组(a,b1,c1)、(a,b2,c2)、(a,b3,c3),那么这个关系中⾄少还应该存在哪些元组?答:(a b1 c2),(a b2 c1),(a b1 c3),(a b3 c1),(a b2 c3),(a b3 c2)评分细则:每⼀个元组1分。

5、简述时间戳排序协议。

答:时间戳:对于系统中的每⼀个事务Ti,我们把⼀个唯⼀的固定的时间戳和它联系起来,记为TS(Ti)。

每个数据项Q需要与两个时间戳相关联:W-timestamp(Q)表⽰成功执⾏write(Q)的所有失去的最⼤时间戳;R-timestamp(Q)表⽰成功执⾏read(Q)的所有事务的最⼤的时间戳。

SQL数据库系统实验报告(含代码、截图)

SQL数据库系统实验报告(含代码、截图)

设有一学籍管理系统,其数据库名为“EDUC”。

初始大小为 10MB,最大为50MB,数据库自动增长,增长方式是按5%比例增长;日志文件初始为2MB,最大可增长到5MB,按1MB增长。

数据库的逻辑文件名为“student_data”, 物理文件名为“student_data.mdf,存放路径为“E:\sql_data”(注意:此文件名必须已经建立的前提下才可以此操作)。

日志文件的逻辑文件名为“student_log”, 物理文件名为“student_log.ldf”,存放路径为“E:\sql_data”。

四.实验步骤1.使用SQL Server Management Studio(简称SSMS)创建数据库。

(1)启动SSMS在开始菜单中:所有程序-SQL Server 2005 -SQL Server Management Studio单击“连接”按钮,便可以进入【SQL Server Management Studio】窗口。

如果身份验证选择的是“混合模式”,则要输入sa的密码。

(2)建立数据库在“对象资源管理器”窗口,建立上述数据库EDUC。

在数据库节点上右击选择新建。

同时建立一个同样属性的数据库EDUC1。

2. 使用向导删除上面建立的数据库。

用SSMS删除建立的数据库EDUC。

3、数据库的分离将刚建好的数据库分离出来,即点击新建的EDUC——任务——分离,将删除连接和更新打一个钩,然后点击确定。

如图所示:4、数据分离出来之后可以附加进去。

即右击数据库——附加——点击添加按钮,找到数据库文件.mdf所存放的路径,然后点击确定,即可以将我们刚所创建的文件添加回去。

五.实验总结通过本次实验,我熟悉了SQL Server 中SQL Server Management Studio的环境,了解了SQL Server 数据库的逻辑结构和物理结构,掌握使用向导创建和删除数据库的方法。

加深了对数据库的认识和理解。

山东大学数据库实验答案2—8

山东大学数据库实验答案2—8

⼭东⼤学数据库实验答案2—8⼭东⼤学数据库实验答案2—8 CREATE TABLE test2_01 ASSELECT SID, NAMEFROM pub.STUDENTWHERE sid NOT IN(SELECT sid FROM pub.STUDENT_COURSE)CREATE TABLE test2_02 ASSELECT SID,NAMEFROM PUB.STUDENTWHERE SID IN(SELECT DISTINCT SIDFROM PUB.STUDENT_COURSEWHERE CID IN(SELECT CID FROM PUB.STUDENT_COURSE WHERESID='200900130417'))CREATE TABLE test2_03 ASselect SID,NAME from PUB.STUDENT where SID in ( select distinct SID from PUB.STUDENT_COURSE where CID in (select CID from PUB.COURSE where FCID='300002') )CREATE TABLE test2_04 ASselect SID,NAME from PUB.STUDENT where SID in ( select distinct SID from PUB.STUDENT_COURSE where CID in (select CID from PUB.COURSE where NAME='操作系统')intersectselect distinct SID from PUB.STUDENT_COURSE where CID in (select CID from PUB.COURSE where NAME='数据结构') )create table test2_05 aswith valid_stu(sid,name) as(select SID,NAME from PUB.STUDENT where AGE=20 and SID in (select SID from PUB.STUDENT_COURSE))select sid,name as name,ROUND(avg(score)) as avg_score,sum(score) as sum_score fromPUB.STUDENT_COURSE natural join valid_stu where SID in (select SID from valid_stu)group by SID,NAMEcreate table test2_06 asselect CID,(max(SCORE))max_score from PUB.STUDENT_COURSE group byCIDcreate table test2_07 asselect SID,NAME from PUB.STUDENT where(NAME not like '张%' and NAME not like '李%' and NAME not like '王%') create table test2_08 aswith xing(value) as (select substr(NAME,1,1) from PUB.STUDENT)select value as second_name,count(value) as p_count from xing group by valuecreate table test2_09 asselect distinct SID,NAME,SCORE from PUB.STUDENT_COURSE natural join PUB.STUDENTwhere CID ='300003';create table test2_10 asselect distinct SID,CID from PUB.STUDENT_COURSE where SID in (select SID from PUB.STUDENT_COURSE) /* 1 */create table test3_01 asselect * from pub.student_31 where regexp_like(SID,'^[0-9]+$')/* 2 */create table test3_02 asselect * from pub.student_31where to_number(substr(BIRTHDAY,8,2))+AGE=112/* 3 */create table test3_03 asselect * from pub.student_31where SEX is null or SEX='男' or SEX='⼥'/* 4 */create table test3_04 asselect * from pub.student_31where DNAME is not null and length(DNAME)>=3 and instr(DNAME,' ')<=0 /* 5 */create table test3_05 asselect * from pub.student_31where regexp_like(CLASS,'^[0-9]{4}$')/* 6 */create table test3_06 asselect * from pub.student_31where regexp_like(SID,'^[0-9]+$')and to_number(substr(BIRTHDAY,8,2))+AGE=112 and (SEX is null orSEX='男' or SEX='⼥')and (DNAME is not null and length(DNAME)>=3 and instr(DNAME,' ')<=0) and regexp_like(CLASS,'^[0-9]{4}$') and (instr(NAME,' ')<=0 and length(NAME)>=2)/* 7 */create table test3_07 asselect * from pub.student_course_32 where SID in (select SID from pub.student)/* 8 */create table test3_08 asselect * from pub.student_course_32 natural join pub.teacher_course /* 9 */create table test3_09 asselect * from pub.student_course_32 where SCORE>=0 and score <=100 /* 10 */create table test3_10 asselect * from pub.student_course_32 natural join pub.teacher_course where SID in (select SID from pub.student) and CID in (select CID from pub.course) and TID in (select TID from pub.teacher) and SCORE>=0 and score <=100/*-------------- test4_01 --------------*/ create table test4_01 as select * from pub.student_41;ALTER TABLE test4_01 ADD sum_score number;update test4_01 set sum_score=(select sum(score) from pub.student_course a wheretest4_01.sid=a.sid group by sid);/*-------------- test4_02 --------------*/create table test4_02 as select * from pub.student_41;ALTER TABLE test4_02 ADD avg_score number;update test4_02 set avg_score =(select round(avg(score),1) from pub.student_course a wheretest4_02.sid=a.sidgroup by sid);/*-------------- test4_03 --------------*/create table test4_03 as select * from pub.student_41;ALTER TABLE test4_03 ADD sum_credit number;update test4_03 set sum_credit =(with a as (select * from pub.student_course natural join pub.course) (select sum(credit) from awhere SCORE>=60 and test4_03.sid=a.sid group by sid) )/* 4 */create table test4_04 as select * from pub.student_41;update test4_04 set dname=(select did from pub.department wheretest4_04.dname=pub.department.dname)where dname in (select dname from pub.department);/* 5 */create table test4_05 as select * from pub.student_41;ALTER TABLE test4_05 add did varchar(2);ALTER TABLE test4_05 ADD sum_score number;ALTER TABLE test4_05 ADD avg_score number;ALTER TABLE test4_05 ADD sum_credit number;update test4_05 set sum_score=(select sum(score) from pub.student_course a wheretest4_05.sid=a.sid group by sid);update test4_05 set avg_score =(select round(avg(score),1) from pub.student_course a wheretest4_05.sid=a.sidgroup by sid);update test4_05 set sum_credit =(with a as (select * from pub.student_course natural join pub.course) (select sum(credit) from awhere SCORE>=60 and test4_05.sid=a.sid group by sid));update test4_05 set did =(select did from pub.department wherepub.department.dname=test4_05.dname) where dname in (select dname from pub.department);update test4_05 set did =(select did from pub.department_41 where pub.department_41.dname=test4_05.dname) where dname in (select dname from pub.department_41);update test4_05 set did ='00' where did is null;/* 6 */create table test4_06 as select * from pub.student_42;update test4_06 set name=replace(name,' ','');/* 7 */create table test4_07 as select * from pub.student_42;update test4_07 set SEX=substr(trim(SEX),1,1) where length(SEX)<>1;/* 8 */create table test4_08 as select * from pub.student_42;update test4_08 set CLASS=substr(CLASS,1,4) where length(CLASS)<>4;/* 9 */create table test4_09 as select * from pub.student_42;update test4_09 set AGE=112-to_number(substr(BIRTHDAY,8,2)) where AGE is null;/* 10 */create table test4_10 as select * from pub.student_42;update test4_10 set name=replace(name,' ',''),DNAME=replace(DNAME,' ','');update test4_10 set SEX=substr(trim(SEX),1,1) where length(SEX)<>1;update test4_10 set CLASS=substr(CLASS,1,4) where length(CLASS)<>4;update test4_10 set AGE=112-to_number(substr(BIRTHDAY,8,2)) where AGE is null;create table test5_10(test varchar(20),age numeric (3));insert into test5_10 values('结果1',88);insert into test5_10 values('结果2',90);insert into test5_10 values('结果3',90);insert into test5_10 values('结果4',86);insert into test5_10 values('结果5',90);insert into test5_10 values('结果6',90);insert into test5_10 values('结果7',86);insert into test5_10 values('结果8',86);insert into test5_10 values('结果9',76);insert into test5_10 values('结果10',86);/* 1 */create view test6_01 asselect sid,name,dname from pub.studentwhere age<20 and dname='物理学院' order by sid/* 2 */create view test6_02 aswith temp_table(sid,ss) as(select sid,sum(score) from pub.student_course group by sid) select sid,name,dname,ss as sum_score from pub.student natural join temp_table where class='2009' and dname='软件学院'/* 3 */create view test6_03 asselect * from pub.student_course natural join pub.student whereclass='2010' and dname='计算机科学与技术学院' and cid =(select cid from pub.course where name='操作系统')/* 4 */create view test6_04 asselect sid,/doc/06a78e778662caaedd3383c4bb4cf7ec4bfeb671.html from pub.student_course natural join pub.studentwhere score>90 and cid =(select cid from pub.course where name='数据库系统')/* 5 */create view test6_05 asselect sid,cid,name,score from pub.student_course natural joinpub.coursewhere sid in (select sid from pub.student where name='李龙')/* 6 */create view test6_06 aswith a as (select sid,count(*) as totc from pub.student_course group by sid)select sid,name from pub.student where sid in (select sid from a where totc>=(selectcount(*) from pub.course))/* 7 */create view test6_07 asselect * from test6_06 where sid not in (select distinct sid from pub.student_course where sid in(select sid from test6_06)and score<60)/* 8 */create view test6_08 asselect cid,name from pub.coursewhere fcid in (select cid from pub.course where credit=2)/* 9 */create view test6_09 aswith a(sid,sum_credit) as(select sid,sum(credit) as sum_creditfrom pub.student_course natural join pub.course where SCORE>=60 group by sid)select sid,name,sum_credit from pub.student natural join a where class='2010' and dname='化学与化⼯学院'/* 10 */create view test6_10 asselect cid,name from pub.coursewhere fcid in(select cid from pub.course where fcid is not null)/* 1 */create table test7_01 asselect First_name,count(*) as frequency from( select substr(NAME,2) as First_name from pub.student ) group by First_name /* 2 */create table test7_02 asselect letter,count(*) as frequency from(select substr(NAME,2,1) as letter from pub.studentunion allselect substr(NAME,3) as letter from pub.student wherelength(Name)=3 ) group by letter/* 3 */create table test7_03 aswith a as (select sid,sum(credit) as tot from pub.student_course natural join pub.course where SCORE>=60 group by sid),b as (select * from pub.student natural left join a),c as (select dname,class,count(sid) as p_count from b group by (dname,class)),d as (select dname,class,count(sid) as p_count1 from b where tot>=10 group by (dname,class)),e as (select dname,class,count(sid) as p_count2 from b where tot<10 or tot is null group by (dname,class))select * from c natural left join d natural join eupdate test7_03 set p_count1=0 where p_count1 is null;/* 4 */create view test7_04_v1 asselect * from pub.student natural left join(select sid,sum(credit) as tot from pub.student_course natural join pub.course where SCORE>=60 group by sid);create table test7_04 aswith b as (select * from test7_04_v1),c as (select dname,class,count(sid) as p_count from b group by (dname,class)),d as (select dname,class,count(sid) as p_count1 from b where class<=2008 and tot>=8 group by (dname,class)unionselect dname,class,count(sid) as p_count1 from b where class>2008 and tot>=10 group by (dname,class))select * from c natural left join d where dname is not null;alter table test7_04 add p_count2 NUMBER;update test7_04 set p_count2 = p_count - p_count1;/* 1 */create table test8_01 aswith A as(select DNAME,SCORE,NAME from(select CID,DNAME,SCORE from pub.student_course natural joinpub.student where dnameis not null) natural join pub.course),B as(select dname,round(avg(score)) as avg_ds_score from A where name='数据结构' groupby dname),C as(select dname,round(avg(score)) as avg_os_score from A where name='操作系统' groupby dname)select * from B natural join C/* 2 */create table test8_02 aswith a as(select sid from pub.student_course where cid=(select cid frompub.course where name='操作系统') intersectselect sid from pub.student_course where cid=(select cid frompub.course where name='数据结构')),b as (select a.sid,score as ds_score from pub.student_course,a where pub.student_course.sid=a.sid and cid=(select cid from pub.course where name='数据结构')),c as (select a.sid,score as os_score from pub.student_course,a where pub.student_course.sid=a.sid and cid=(select cid from pub.course where name='操作系统'))select sid,name,dname,ds_score,os_score from b natural join cnatural join pub.student where dname='计算机科学与技术学院' /* 3 */create table test8_03 aswith a as(select sid from pub.student_course where cid=(select cid frompub.course where name='操作系统') unionselect sid from pub.student_course where cid=(select cid frompub.course where name='数据结构')),b as (select a.sid,score as ds_score from pub.student_course,a where pub.student_course.sid=a.sid and cid=(select cid from pub.course where name='数据结构')),c as (select a.sid,score as os_score from pub.student_course,a wherepub.student_course.sid=a.sid and cid=(select cid from pub.course where name='操作系统'))select sid,name,dname,ds_score,os_score from b natural full join c natural join pub.student where dname='计算机科学与技术学院' /* 4 */create table test8_04 aswith a as(select sid from pub.student_course where cid=(select cid frompub.course where name='操作系统') unionselect sid from pub.student_course where cid=(select cid frompub.course where name='数据结构')),b as (select a.sid,score as ds_score from pub.student_course,a where pub.student_course.sid=a.sid and cid=(select cid from pub.course where name='数据结构')),c as (select a.sid,score as os_score from pub.student_course,a where pub.student_course.sid=a.sid and cid=(select cid from pub.course where name='操作系统'))select sid,name,dname,ds_score,os_score from b natural full join c natural full join pub.student where dname='计算机科学与技术学院'。

SQL部分模拟试题及答案(第2套).docx

SQL部分模拟试题及答案(第2套).docx

SQL部分模拟试题(二)一、单项选择题(本大题共12小题,每小题2分,共24分)1、数据库(DB),数据库系统(DBS)和数据库管理系统(DBMS)之间的关系是_______________ 。

( )A.DBMS 包括DB 和DBSB. DBS 包扌舌DB 和DBMSC. DB包括DBS和DBMSD D・BS就是DB,也就是DBMS2、SQL Server的_________ 允许用户输入SQL语句并且迅速查看这些语句的结果。

()A.查询分析器B.服务管理器C.事件探测器D.企业管理器3、以下哪个操作可以创建数据库。

()A.进入查询分析器,选择菜单命令“工具”-> “向导”,打开“选择向导”对话框,在对话框中,展开“注册服务器向导”屮的“数据库”文件夹,选屮“创建数据库向导”项B.进入服务管理器,选择菜单命令“工具”一“向导”,打开“选择向导”对话框,在对话框中,展开“注册服务器向导”中的“数据库”文件夹,选中“创建数据库向导”项C.进入事件探测器,选择菜单命令“工具”一“向导”,打开“选择向导”对话框,在对话框中,展开“注册服务器向导”中的“数据库”文件夹,选中“创建数据库向导”项D.进入企业管理器,选择菜单命令“工具”一“向导”,打开“选择向导”对话框,在对话框屮,展开“注册服务器向导”中的“数据库”文件夹,选中“创建数据库向导”项4、下面所列条目中,哪一条不是标准的SQL语句?()A.ALTERTABLEB. ALTERV1EWC. CREATETABLED. CREATEVIEW5、若要在基本表S中增加一列CN (课程名),可用____________ o ()A.ADD TABLES (CN CHAR ( 8 ))B. ADD TABLES ALTER (CN CHAR ( 8 ))C. ALTER TABLES ADD (CN CHAR ( 8 )) D・ ALTER TABLES (ADD CN CHAR ( 8 ))6、取出关系屮的某些列,并消去重复的元组的关系运算称为__________ o ()A.取列运算B.投影运算C.连接运算D.选择运算7、在SQL语言中,条件“ BETWEEN20AND30 ”表示年龄在20到30之间,且___________ 。

SQL考试试题

SQL考试试题
按部门编号升序排列。显示格式为:名字 编号 工作 部门名称。(2分)
7. 使用EXP命令导出Scott用户下的所有数据库对象,存放在文件中,文件名为:
E:\新建目录下学员姓名。(2分)
(4)OrderItems表(记录订单信息)
订单代码(oid):普通编码定长字符串,长度3,主键;
代理商代码(aid):普通编码定长字符串,长度3,非空;
客户代码(cid):普通编码定长字符串,长度4,非空;
商品代码(pid):普通编码定长字符串,长度4,非空;
数量(oquantity) :整型,默认值为0;
(2)Client表结构(记录客户信息)
客户代码(cid):普通编码定长字符串,长度4,主键;
客户姓名(cname):统一编码变长字符串,长度6,非空;
所在城市(ccity):统一编码变长字符串,长度8,取值范围为{北京,天津,广州,
济南};
折扣率(cdiscnt):普小数点后保留2位,小数点前4位,默认值为0。
山东省计算机审计第八期中级培训班结业试题
数据库应用技术 上机考试试卷 (1)
说明:考试结束,不要关机,请老师确认;离场前,将试卷填写学号、姓名、机器号放
在机器键盘下!
要求:在E:\根目录下用自己的姓名拼音加"DB"建立一个文件夹。(例:姓名为王平
的考生建立文件夹"E:\WangpingDB" ),考试中所有的文件必须按照要求放在该文件
夹下!否则不得分!
一、创建数据库、数据表以及数据导入操作。
本题共15分,其中第1小题3分,第2小题8分,第3小题4分。
在SQL Server 2008中,使用SQL Management Studio建立满足如下要求的数据库。

山东大学人工智能实验一八数码问题

山东大学人工智能实验一八数码问题
import java.io.*; import java.util.*; /** * 八数码问题的实现 * @author sdu20 * */ public class EightPuzzle implements Comparable{ private int[] num = new int[9]; private int depth; private int evaluation; private int misposition; private EightPuzzle parent; public int[] getNum() { return num; } public void setNum(int[] num) { //当前的深度即走到当前状态的步骤 //从起始状态到目标的最小估计值 //到目标的最小估计 //当前状态的父状态
山东大学计算机科学与技术学院 人工智能课程实验报告
学号:2420430689 实验题目: 八数码问题 实验学时: 2 实验日期: 姓名: QQ 班级: 2014 级 1 班
实验目的: 熟悉和掌握启发式搜索的定义、估价函数和算法过程,并利用启发式搜 索算法求解八数码难题,理解求解流程和搜索顺序。 硬件环境: PC 机 软件环境: eclipse 实验步骤与内容: 1、根据实验指导书及课本上关于八数码问题的算法介绍编写程序代码如下:
this.num = num; } public int getDepth() { return depth; } pubth = depth; } public int getEvaluation() { return evaluation; } public void setEvaluation(int evaluation) { this.evaluation = evaluation; } public int getMisposition() { return misposition; } public void setMisposition(int misposition) { this.misposition = misposition; } public EightPuzzle getParent() { return parent; } public void setParent(EightPuzzle parent) { this.parent = parent; } /** * 判断当前状态是否为目标状态 * @param target * @return */ public boolean isTarget(EightPuzzle target){ return Arrays.equals(getNum(), target.getNum()); } /** * 求 f(n) = g(n)+h(n); * 初始化状态信息 * @param target */ public void init(EightPuzzle target){ int temp = 0; for(int i=0;i<9;i++){

2022年山东大学数据科学与大数据技术专业《数据库系统原理》科目期末试卷B(有答案)

2022年山东大学数据科学与大数据技术专业《数据库系统原理》科目期末试卷B(有答案)

2022年山东大学数据科学与大数据技术专业《数据库系统原理》科目期末试卷B(有答案)一、填空题1、在SELECT命令中进行查询,若希望查询的结果不出现重复元组,应在SEL ECT语句中使用______保留字。

2、在SELECT命令中,______子句用于选择满足给定条件的元组,使用______子句可按指定列的值分组,同时使用______子句可提取满足条件的组。

3、对于非规范化的模式,经过转变为1NF,______,将1NF经过转变为2NF,______,将2NF经过转变为3NF______。

4、如图所示的关系R的候选码为;R中的函数依赖有;R属于范式。

一个关系R5、在设计局部E-R图时,由于各个子系统分别有不同的应用,而且往往是由不同的设计人员设计,所以各个局部E-R图之间难免有不一致的地方,称为冲突。

这些冲突主要有______、______和______3类。

6、某在SQL Server 2000数据库中有两张表:商品表(商品号,商品名,商品类别,成本价)和销售表(商品号,销售时间,销售数量,销售单价)。

用户需统计指定年份每类商品的销售总数量和销售总利润,要求只列出销售总利润最多的前三类商品的商品类别、销售总数量和销售总利润。

为了完成该统计操作,请按要求将下面的存储过程补充完整。

7、数据库系统是利用存储在外存上其他地方的______来重建被破坏的数据库。

方法主要有两种:______和______。

8、数据仓库创建后,首先从______中抽取所需要的数据到数据准备区,在数据准备区中经过净化处理______,再加载到数据仓库中,最后根据用户的需求将数据发布到______。

9、数据库管理系统的主要功能有______________、______________、数据库的运行管理以及数据库的建立和维护等4个方面。

10、数据仓库主要是供决策分析用的______,所涉及的数据操作主要是______,一般情况下不进行。

山东大学数据库DB实验8

山东大学数据库DB实验8
1.create table tmp as select dname,round(avg(score),0) as avg_ds_score from pub.student,pub.student_course,pub.course where pub.student.sid=pub.student_course.sid and pub.course.cid=pub.student_course.cid and dname is not null and ='数据结构' group by dname
create table test8_01 as select tmp.dname,tmp.avg_ds_score,tmp1.avg_os_score from tmp,tmp1 where tmp.dname=tmp1.dname
drop table tmp
drop table tmp1
2.create table tmp as select pub.student.sid,,dname,score as ds_score from pub.student,pub.student_course,pub.course where pub.student.sid=pub.student_course.sid and pub.course.cid=pub.student_course.cid and dname='计算机科学与技术学院' and ='数据结构' and in (select from pub.student,pub.student_course,pub.course where pub.student.sid=pub.student_course.sid and pub.course.cid=pub.student_course.cid and dname='计算机科学与技术学院' and ='操作系统')
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Test2(1)create table test2_01 as select sid,nameFrom pub.student pwhere not exists (select cid from pub.student_course where sid=p.sid)(2)create table test2_02 as select sid,nameFrom pub.student natural join pub.student_courseWhere cid in (select cid from pub.student_course where sid=’200900130417’)(3)create table test2_03 as select sid,nameFrom pub.student natural join pub.student_courseWhere cid in (select cid from pub.course where fcid=’300002’)(4)create table test2_04 as select sid,nameFrom pub.studentWhere sid in(select sid from pub.course ,pub .student_course where student_course.cid=course.cid and name='操作系统' )Andsid in(select sid from pub.course ,pub .student_course where student_course.cid=course.cid and name='数据结构' )(5)create table test2_05 as select student.sid,name,cast(avg(score) as numeric(5,0)) avg_score, sum (score) sum_scorefrom pub.student_course,pub.studentWhere pub.student_course.sid=pub.student.sid and age='20'group by student.sid,name(6)create table test2_06 as select cid,max(score)max_scoreFrom pub.student_courseGroup by cid(7)create table test2_07 as select sid,nameFrom pub.studentWhere name not in (select name from pub.student where name like (‘张%’) or name like (‘李%’) or name like (‘王%’)(8)create table test2_08 as select substr(name,1,1) second_name,count (*) p_countFrom pub.studentGroup by substr(name,1,1)(9)create table test2_09 as select pub.student.sid,name,scoreFrom pub.student,pub.student_courseWhere pub.student.sid=pub.student_course.sid and cid='300003'(10)create table test2_10 as select sid,cidFrom pub.student_courseWhere score is not nullTest3(1)create table test3_01 as select * from pub.Student_31delete from test3_01 where length(translate(sid,'\0123456789','\'))>0(2)create table test3_02 as select * from pub.Student_31delete from test3_02 where age<>2012-extract(year from birthday)(3)create table test3_03 as select * from pub.Student_31delete from test3_03 where sex not in (select sex from test3_03 where sex='男' or sex='女' or sex=null) (4)create table test3_04 as select * from pub.Student_31delete from test3_04 where dname is null or length(dname)<3 or dname like '% %'(5)create table test3_05 as select * from pub.Student_31delete from test3_05 where length(class)>4(6)create table test3_06 as select * from pub.Student_31delete from test3_06 where length(translate(sid,'\0123456789','\'))<12Delete from test3_06 where age<>2012-extract(year from birthday)Delete from test3_06 where sex not in (select sex from test3_03 where sex='男' or sex='女' or sex=null) Delete from test3_06 where dname is null or length(dname)<3 or dname like '% %'delete from test3_06 where length(class)>4delete from test3_06 where name like '% %' or length(name)<2(7)create table test3_07 as select * from pub.Student_course_32delete from test3_07 where sid not in (select sid from pub.student)(8)create table test3_08 as select * from pub.Student_course_32delete from test3_08 where (cid,tid) not in (select cid,tid from pub.teacher_course)(9)create table test3_09 as select * from pub.Student_course_32delete from test3_09 where score <0 or score >100(10)create table test3_10 as select * from pub.Student_course_32delete from test3_10 where score <0 or score >100delete from test3_10 where sid not in (select sid from pub.student)delete from test3_10 where cid not in (select cid from pub.course)delete from test3_10 where tid not in (select tid from pub.teacher)delete from test3_10 where (cid,tid) not in (select cid,tid from pub.teacher_course)Test 4(1)create table test4_01 as select * from pub.student_41alter table test4_01 add sum_score numberupdate test4_01 set sum_score = (select sum (score) from pub.student_course where test4_01.sid= pub.student_course.sid)(2)create table test4_02 as select * from pub.student_41alter table test4_02 add avg_score numeric(5,1)update test4_02 set avg_score = (select avg (score) from pub.student_course where test4_02.sid= pub.student_course.sid)(3)create table test4_03 as select * from pub.student_41alter table test4_03 add sum_credit intcreate table t4_031 as select * from pub.course natural join pub.student_courseupdate t4_031 set credit=0 where score<60update test4_03 set sum_credit = (select sum(credit) from t4_031 where test4_03.sid=t4_031.sid) (4)create table test4_04 as select * from pub.student_41update test4_04 set dname=(select did from pub.department where pub.department.dname=test4_04.dname)where dname in (select dname from pub.department)(5)create table test4_05 as select * from pub.student_41alter table test4_05 add sum_score numberalter table test4_05 add avg_score numeric(5,1)alter table test4_05 add sum_credit intalter table test4_05 add did varchar(2)update test4_05 set sum_score =(select sum (score) from pub.student_course where test4_05.sid= pub.student_course.sid)update test4_05 set avg_score = (select avg (score) from pub.student_course where test4_05.sid= pub.student_course.sid)update test4_05 set sum_credit = (select sum(credit) from t4_031 where test4_05.sid=t4_031.sid) create table a1 as select * from pub.departmentinsert into a1 select * from pub.department_41 where dname not in (select distinct dname from pub.department )(6)create table test4_06 as select * from pub.student_42update test4_06 set name =replace(name,' ','')(7)create table test4_07 as select * from pub.student_42update test4_07 set sex =replace(sex,'性','')update test4_07 set sex =replace(sex,' ','')(8)create table test4_08 as select * from pub.student_42update test4_08 set class=replace(class,'级','')update test4_08 set class=replace(class,' ','')(9)create table test4_09 as select * from pub.student_42update test4_09 set age=2012-extract(year from birthday) where age is null(10)create table test4_10 as select * from pub.student_42update test4_10 set name=replace(name,' ','')update test4_10 set dname=replace(dname,' ','')update test4_10 set sex=replace(sex,'性','')update test4_10 set sex=replace(sex,' ','')update test4_10 set class=replace(class,'级','')update test4_10 set class=replace(class,' ','')update test4_10 set age=2012-extract(year from birthday) where age is nullTest5create table test5_10 (test varchar(20),age numeric (3))insert into test5_10values ('结果1',88),insert into test5_10values ('结果2',90),insert into test5_10values ('结果3',90),insert into test5_10values ('结果4',86),insert into test5_10values ('结果5',90),insert into test5_10values ('结果6',90),insert into test5_10values ('结果7',86),insert into test5_10values ('结果8',86),insert into test5_10values ('结果9',76),insert into test5_10values ('结果10',86)Test6(1) create view test6_01 as select sid,name,dname from pub.student where age<20 and dname='物理学院'order by sid(2)create view test6_02 as select pub.student.sid,name,sum(score)sum_score from pub.student,pub.student_course where pub.student.sid=pub.student_course.sid and class='2009' and dname='软件学院' group by pub.student.sid,(3)create view test6_03 as select pub.student.sid,,pub.student_course.score from pub.student,pub.student_course where pub.student.sid=pub.student_course.sid and class='2010' and dname='计算机科学与技术学院' and pub.student_course.cid=(select cid from pub.course where ='操作系统')(4)create view test6_04 as select pub.student.sid, from pub.student,pub.student_course where pub.student.sid=pub.student_course.sid and score>90 and pub.student_course.cid=(select cid from pub.course where ='数据库系统')(5)create view test6_05 as select pub.student_course.sid,pub.student_course.cid,score, from pub.course,pub.student_course,pub.student where pub.course.cid=pub.student_course.cid and pub.student_course.sid=pub.student.sid and ='李龙'(6)create view test6_06 as select sid,name from pub.student where sid in (select sid from pub.student_course group by sid having count(*) >=(select count(*) from pub.course ))(7)create view test6_07 as select sid,name from pub.student where sid in (select sid from pub.student_course where score>=60 group by sid having count(*) >=(select count(*) from pub.course ))(8)create view test6_08 as select a1.cid, from pub.course a1,pub.course a2 where a1.fcid =a2.cid and a2.credit=2(9)create view test6_09 as select pub.student.sid, ,sum(credit) sum_credit from pub.student, pub.student_course,pub.course where pub.student.sid = pub.student_course.sid and pub.student_course.cid=pub.course.cid and class='2010' and dname='化学与化工学院' and score>=60 group by pub.student.sid, (10)create view test6_10 as select a1.cid, from pub.course a1,pub.course a2 where a1.fcid=a2.cid and a2.fcid is not nullTest7(1)create table a as select (substr(name,2)) first_name from pub.student create table test7_01 as select first_name,(count(*)) frequency from a group by first_name(2)Union和Union All的区别之一在于对重复结果的处理。

相关文档
最新文档