数据库SQL综合分析题

数据库SQL综合分析题,第1张

前言:只有答案没有分析,大家可以去网上找找怎么分析执行过程。 

1. (简答题, 40分)

假设学生-课程数据库关系模式如下所示:

Student(S#,Sname,Sage,Ssex)表示学生关系,属性为学号、姓名、年龄、性别;

Course(C#,Cname,Ccredit)表示课程关系,属性为课程号、课程名,学分;

SC(S#,C#,Score)表示选修关系,属性为学号、课程号、考试成绩;

各表中数据见下面表格所示,请说明:

(1)下面SQL语句的功能。

(2)执行过程。

(3)查询结果。

本题满分40分,其中SQL语句功能10分;语句的执行过程20分,请从SQL语句各子句的执行次序角度分析该语句的执行过程;查询结果10分,可用表格形式给出。

SELECT  Student.S#,Sname,Sage,SUM(Ccredit) SumCredit

FROM Student,SC,Course

WHERE Student.S#=SC.S# AND Course.C#=SC.C# AND Ssex='女' AND Score>=60

GROUP BY Student.S#,Sname,Sage Having Count(*)>2

ORDER BY SumCredit DESC,Sname ASC;

create table Student(
S# char(5) primary key,
Sname char(20),
Sage number,
Ssex char(2)
);
create table Course(
C# char(5)primary key,
Cname char(20),
Ccredit char(5)
);
create table SC(
S# char(5),
C# char(5),
Score number,
primary key(S#,C#),
foreign key(S#) references Student(S#),
foreign key(C#) references Course(C#)
);
insert into Student values('101','李红梅',20,'女');
insert into Student values('102','李琳琳',19,'女');
insert into Student values('103','张强',20,'男');
insert into Student values('104','谭莉',21,'女');
insert into Student values('105','赵茂盛',18,'男');
insert into Student values('106','李晓光',19,'男');
insert into Student values('107','何虹',20,'女');
insert into Student values('108','王美丽',21,'女');
insert into Student values('109','吴嫦娥',29,'女');
insert into COURSE values('1','高级语言程序设计','3');
insert into COURSE values('2','大学英语1','3');
insert into COURSE values('3','数据结构','3.5');
insert into COURSE values('4',' *** 作系统原理','3');
insert into COURSE values('5','Python程序设计','2');
insert into COURSE values('6','高等数学','4.5');
insert into SC values ('101','1',80);
insert into SC values ('101','2',75);
insert into SC values ('101','3',90);
insert into SC values ('101','4',87);
insert into SC values ('102','1',85);
insert into SC values ('102','3',75);
insert into SC values ('102','6',90);
insert into SC values ('103','1',70);
insert into SC values ('103','2',65);
insert into SC values ('103','3',85);
insert into SC values ('104','2',75);
insert into SC values ('104','3',88);
insert into SC values ('104','4',77);
insert into SC values ('105','1',90);
insert into SC values ('105','2',87);
insert into SC values ('106','1',72);
insert into SC values ('107','2',76);
insert into SC values ('108','1',75);
insert into SC values ('108','2',55);
insert into SC values ('108','3',70);
insert into SC values ('109','1',75);
insert into SC values ('109','3',75);
insert into SC values ('109','5',75);

SELECT  Student.S#,Sname,Sage,SUM(Ccredit) SumCredit

FROM Student,SC,Course

WHERE Student.S#=SC.S# AND Course.C#=SC.C# AND Ssex='女' AND Score>=60

GROUP BY Student.S#,Sname,Sage Having Count(*)>2

ORDER BY SumCredit DESC,Sname ASC;

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/991549.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存