您的当前位置:首页正文

数据库操作题03

2020-11-26 来源:步旅网


SQL设计

打开并运行X:/XSGL.sql文件,创建XSGL数据库。

试完成以下查询,分别存储为题号.sql,如:A.sql、B.sql……J.sql。

A. 查询年龄为19岁的“刘”姓学生。

B. 查询“李勇”选修的所有课程及成绩,显示结果为姓名,课程名,成绩。(用连接实现)

C. 查询“李勇”选修的所有课程的课程名程。(用嵌套查询实现)

D. 查询和“刘晨”在同一个系学习的其他同学的信息。

E. 查询每个系的学生数,显示结果为系名,人数。

F. 查询选修的课程数超过(含)3门的学生的学号。

G. 查询平均成绩在80分以上(含)的学生的姓名。

H. 查询至少选修了“95001”选的全部课程的学生的姓名。

I. 将女同学选修的“3”号课程成绩提高10%。

J. 删除还没有成绩的选课信息。(成绩为空)

SQL设计·参考答案:

--A.查询年龄为19岁的“刘”姓学生

select * from student where Sage=19 and sname like '刘%'

--B.查询“李勇”选修的所有课程及成绩,显示结果为姓名,课程名,成绩。(用连接实现)

select sname,cname,grade

from Student,Course,SC

where student.sno=sc.sno and Course.cno=SC.cno and sname='李勇'

--C.查询“李勇”选修的所有课程的课程名程。(用嵌套查询实现)

select cname from course

where cno in

(select cno from sc where sno in

(select sno from student where sname='李勇')

)

--D.查询和“刘晨”在同一个系学习的其他同学的信息。

select * from student

where Sdept=

(select Sdept from student where sname='刘晨') and sname<>'刘晨'

--E.查询每个系的学生数,显示结果为系名,人数。

select SDept as 系名,count(*) as 人数

from student

group by SDept

--F.查询选修的课程数超过(含)3门的学生的学号。

select sno from sc

group by sno having count(*)>=3

--G.查询平均成绩在80分以上(含)的学生的姓名。

select sname from student

where sno in

(select sno from sc

group by sno having AVG(Grade)>=80)

--H.查询至少选修了“95001”选的全部课程的学生的信息。

select sname

from student

Where not Exists

(select * from SC Sc1

where sno in ('95001') and not Exists

(select * from SC where Sc.sno=Student.sno and Sc1.cno=SC.cno))

--I.将女同学的“3”号课程成绩提高10%。

update sc set Grade=Grade*1.1

where cno='3' and sno in(select sno from student where SSEX='女')

--J.删除还没有成绩的选课信息。(成绩为空)

delete from SC where Grade is NULL

因篇幅问题不能全部显示,请点此查看更多更全内容