学生管理系统MS数据库练习(2)

use student

create table course

(

cno char(7) constraint fk_co primary key,

cname char(30) not null,

credits real not null

)

insert into course

values(‘1001’,‘Illustrator平面设计’,90)

insert into course

values(‘1002’,‘Photoshop图像处理’,80)

insert into course

values(‘1003’,‘Dreamweaver网页制作’,70)

insert into course

values(‘1004’,‘数据结构’,60)

CREATE TABLE department

(

deptno char(2) constraint pk_dept primary key,

deptname char(20) not null

)

CREATE TABLE professional

(

pno char(4) constraint pk_pro primary key,

pname char(30) not null,

deptno char(2)

)

INSERT INTO department

VALUES(‘01’,‘计算机工程系’)

INSERT INTO department

VALUES(‘02’,‘商贸管理系’)

INSERT INTO department

VALUES(‘03’,‘外语系’)

INSERT INTO department

VALUES(‘04’,‘机电工程系’)

INSERT INTO department

VALUES(‘05’,‘化学工程系’)

INSERT INTO department

VALUES(‘06’,‘物理系’)

INSERT INTO department

VALUES(‘11’,‘信息系’)

INSERT INTO professional

VALUES(‘0101’,‘计算机应用技术’,‘01’)

INSERT INTO professional

VALUES(‘0102’,‘计算机网络技术’,‘01’)

INSERT INTO professional

VALUES(‘0201’,‘物流管理’,‘02’)

INSERT INTO professional

VALUES(‘0202’,‘会计’,‘02’)

INSERT INTO professional

VALUES(‘0301’,‘德语’,‘03’)

INSERT INTO professional

VALUES(‘0302’,‘商务英语’,‘03’)

INSERT INTO professional

VALUES(‘0401’,‘模具设计与制造’,‘04’)

INSERT INTO professional

VALUES(‘0402’,‘机电一体化技术’,‘04’)

INSERT INTO professional

VALUES(‘0501’,‘有机化工生产技术’,‘11’)

INSERT INTO professional

VALUES(‘0502’,‘精细化学品生产技术’,‘11’)

CREATE TABLE class

(

classno char(8) constraint pk_class primary key,

classname char(16) not null,

pno char(4) constraint fk_class references professional(pno)

)

INSERT INTO class

VALUES(‘07010211’,‘网络0711’,‘0102’)

INSERT INTO class

VALUES(‘06010111’,‘计应0611’,‘0101’)

INSERT INTO class

VALUES(‘06020111’,‘物流0611’,‘0201’)

INSERT INTO class

VALUES(‘06020211’,‘会计0611’,‘0202’)

INSERT INTO class

VALUES(‘07010111’,‘计应0711’,‘0501’)

–实验7 数据查询(3)——查询排序与查询结果存储

–1. 查询课程信息,按课程名称降序排序

select *

from course

order by cname desc

–2. 查询选修了1001号课程成绩非空的学生学号和成绩,并按成绩降序排序

select student.sno,choice.grade

from student join choice

on student.sno=choice.sno

where cno=‘1001’ and grade<>‘’

order by grade desc

–3. 查询11系学生学号、姓名和年龄,按年龄升序排序

select student.sno,sname,YEAR(getdate())-YEAR(sbirthday)

from student join class

on student.classno=class.classno

join professional

on class.pno=professional.pno

where deptno=‘11’

–实验8 数据查询(4)——查询统计与汇总

–4. 查询课程总数

select COUNT(*)

from course

–5. 查询选修1001号课程的学生人数

select COUNT(*)

from student

where sno in (select sno

from choice

where cno=‘1001’)

–6. 查询被选修课程的数量

select COUNT(*)

from course

where cno in (select cno

from choice)

–7. 查询选修070101班学生的平均入学成绩

select AVG(sscore)

from student

where classno=‘07010211’

–8. 查询070101001号学生选修课程的数量、总分以及平均分

select COUNT(*),SUM(grade),AVG(grade)

from student join choice

on student.sno=choice.sno

where student.sno=‘0701011101’

–9. 查询选修1001号课程的学生人数、最高分、最低分和平均分

select COUNT(*),max(grade),MIN(grade)

from student join choice

on student.sno=choice.sno

where cno=‘1001’

–10. 求各个课程号和相应的选课人数

select cno,COUNT(*)

from choice join student

on choice.sno=student.sno

group by cno

–11. 依次按班级、系号对学生进行分类统计人数、入学平均分

select classno,COUNT(*),AVG(sscore)

from student

group by classno

select deptno,COUNT(*),AVG(sscore)

from student join class

on student.classno=class.classno

join professional

on class.pno=professional.pno

group by deptno

–12. 查询选修了均分在75以上的课程号及均分

select *

from

(select sno,AVG(grade)as score

from choice

group by sno)as a

where score>‘75’

–13. 查询选修了2门以上课程的学生学号

select sno

from

(select student.sno,COUNT(*) as count

from student join choice

on student.sno=choice.sno

group by student.sno)as aa

where count>2

–14. 明细汇总年龄<20的学生,并汇总学生数量、平均年龄

select *

from student

where YEAR(getdate())-YEAR(sbirthday)<20

select COUNT(*),AVG(YEAR(getdate())-YEAR(sbirthday))

from student

–15. 按班级明细汇总成绩<85分的学生,汇总学生数、均分

select classno,COUNT(*),AVG(grade)

from student join choice

on student.sno=choice.sno

where grade<‘80’

group by classno

–实验9 数据查询(5)——连接查询

–16. 用SQL Server形式连接查询学生学号、姓名、性别及其所选课程编号

select student.sno,sname,ssex,cno

from student join choice

on student.sno=choice.sno

order by sno

–17. 用SQL Server形式连接查询学生学号、姓名及其所选课程名称及成绩

select student.sno,sname,ssex,cname,grade

from student join choice

on student.sno=choice.sno

join course

on choice.cno=course.cno

–18. 查询选修了1002课程的学生学号、姓名及1001课程成绩

select student.sno,sname,cno,grade

from student join choice

on student.sno=choice.sno

where cno in(‘1001’,‘1002’)

–19. 查询选修了“数据结构”课程的学生学号、姓名及课程成绩

select student.sno,sname,ssex,grade

from student join choice

on student.sno=choice.sno

join course

on choice.cno=course.cno

where cname=‘数据结构’

–20. 用左外连接查询没有选修任何课程的学生学号、姓名

select student.sno,sname

from student left join choice

on student.sno=choice.sno

where choice.sno is null

–21. 用右外连接查询选修各个课程的学生学号

select distinct student.sno

from student right join choice

on student.sno=choice.sno

–实验10 数据查询(6)——数据更新与子查询

–22. 用子查询对各班人数进行查询(新增列)

select classno,COUNT(*)

from student

group by classno

–23. 查询选修了1002课程成绩不及格的学生的学号、姓名和性别,并按姓名升序排序

select sno,sname,ssex

from student

where sno in(select sno

from choice

where grade<‘60’ and cno=‘1002’)

order by sname asc

–24. 查询“东方红”同学所在班的学生信息,并按姓名降序排序

select *

from student

where classno=(select classno

from student

where sname=‘东方红’)

order by sname desc

–25. 将有不及格成绩的学生的st_mnt值更改为3

update student

set st_mnt=3

where sno in (select sno

from choice

where grade<‘60’)

–26. 删除5系学生的选课信息

DELETE FROM choice WHERE sno in (select sno

from student

where classno in(select classno

from class

where pno in (select pno

from professional

where deptno=‘01’)))

–1.自定义函数

–(1)创建自定义函数stu_sr,该函数可以变换出生日期字段的显示效果

use student

go

create function stu_sr(@stu_sb datetime) returns nvarchar(50)

as

begin

return STR(YEAR(@stu_sb))+‘年’+LTRIM(STR(month(@stu_sb)))+‘月’

end

go

alter function stu_sr(@stu_sb datetime) returns nvarchar(50)

as

begin

declare @sbyear nvarchar(10) =STR(YEAR(@stu_sb))

declare @sbmonth nvarchar(10) =LTRIM(STR(month(@stu_sb)))

if @sbmonth>9

return @sbyear+‘年cname=@cname)

go

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数前端工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Web前端开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上前端开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:前端)

最后

本人分享一下这次字节跳动、美团、头条等大厂的面试真题涉及到的知识点,以及我个人的学习方法、学习路线等,当然也整理了一些学习文档资料出来是附赠给大家的。知识点涉及比较全面,包括但不限于前端基础,HTML,CSS,JavaScript,Vue,ES6,HTTP,浏览器,算法等等

详细大厂面试题答案、学习笔记、学习视频等资料领取,点击资料领取直通车免费领取!

前端视频资料:
(img-iVV5pbKr-1713779041563)]

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上前端开发知识点,真正体系化!

[外链图片转存中…(img-urfyqgP6-1713779041564)]

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:前端)

[外链图片转存中…(img-c5ucGhTf-1713779041564)]

最后

本人分享一下这次字节跳动、美团、头条等大厂的面试真题涉及到的知识点,以及我个人的学习方法、学习路线等,当然也整理了一些学习文档资料出来是附赠给大家的。知识点涉及比较全面,包括但不限于前端基础,HTML,CSS,JavaScript,Vue,ES6,HTTP,浏览器,算法等等

详细大厂面试题答案、学习笔记、学习视频等资料领取,点击资料领取直通车免费领取!

[外链图片转存中…(img-S7o0LkpV-1713779041564)]

前端视频资料:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值