数据库代码——实验四

 

一、 实验准备及任务 

1.复习教材上 SQL 语言中 select 命令和带有子查询的 insert、update、delete 命令。 

2.使用教师已经录入相关数据的附录的“xsglsjk”数据库,完成以下查询,预先写好相应的命令。 

(1) 查询姓名中第二个字为“勇”的男学生的姓名和班级。 

(2) 查询成绩为 68、78、88 98 的选修记录。 

(3) 查询选修了“4”号课程没有成绩的学生学号。 

(4) 查询“00311”班所有女生的学号、姓名和出生年份。 

(5) 查询“李勇敏”同学的班长姓名。 

(6) 查询“2001102”同学的选课门数。 

(7) 统计学生表中的班级数。 

(8) 查询“00311”班每位同学的课程平均分。 

(9) 查询哪些学生最低分大于 70,最高分小于 90,输出他们的学号。 

(10) 计算Student×Cj×Course的结果。

(11)  clno 升序、Sage 降序列出Student表的学生信息。 

(12) 列出成绩高于学号为“2000101”、课程号为“3”的成绩的所有选课记录。 

(13) 查询和“张婷婷”同学在同一班级的学生信息。

(14) 查询不及格课程在三门及以上的同学。 

(15) *查询选修了目前Course中所有课程的同学。 

3. 完成带有子查询的 insert、update、delete 的任务,预先写好相应的命令。 

(16) 对每位同学,求平均成绩,并把结果存入新建立的表中。 

(17) 将班级号为“01312”班级的所有女学生的成绩加 5 分。 

(18) 删除“01311”班级的所有学生的成绩记录。 

 

复制代码

select sname,clno --1
from Student
where Ssex='男'and Sname like '_勇%';



select * --(2)
from Cj
where Grade in (68,78,88,98);



select Sno --3
from Cj
where Cno=4 and Grade is NULL;


select Sno,sname,2022-sage 出生年月 --4
from Student
where Ssex='女'and Clno=00311;



select sname --5
from Student
where Sno in
(select Monitor
from Class
where clno in
(select Clno
from Student
where sname='李勇敏'));



select COUNT(*) --6
from Cj
where Sno=20011020;



select COUNT(distinct Clno) --7
from Student;



select AVG(grade) --8
from Cj
where Sno in
(select Sno
from Student
where Clno=00311)



select sno --9
from Cj
where Grade between 70 and 90;



select --10
Student.Sno,sname,ssex,sage,grade,clno
from Student,Cj,Course
where Student.Sno=Cj.Sno;



select * --11
from Student
order by clno ,Sage desc;



select * --12
from Cj
where Grade > (select Grade
from Cj
where Sno=2000101and Cno=3);



select * --13
from Student
where Clno in
(select Clno
from Student
where Sname='张婷婷')


select sname --14
from Student
where Sno in
(select Sno
from Cj
where Grade<60
group by Sno
having count(Grade) >=3 )



select sname --15
from Student
where Sno in (select Sno
from Cj
group by Sno
having COUNT(Cno)=7)


-------------------------------------------
create table Avg_grade ---16
(sno varchar(20) NULL,
AVG_grades decimal(4, 1) NULL);


insert
into Avg_grade(sno,AVG_grades)
select sno,AVG(grade)
from Cj
group by Sno ;


----------------------------------------------


update Cj --17
set Grade=Grade+5
where Sno in (select Sno
from Student
where clno=01312 and ssex='女')



delete --18
from Cj
where Sno in
(select Sno
from Student
where Clno=01311
)


复制代码

 

 

null
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示