当前位置:网站首页>数据库查询 - 选课系统
数据库查询 - 选课系统
2022-04-23 19:28:00 【x 心 动】
/*
仅供参考:切勿躺尸!!!
*/
第1关:数据库数据的插入
USE School;
#请在此添加实现代码
########## Begin ##########
########## 插入学生表(Student)相应数据 ##########
insert into student values('9512101','李勇 ','男','19','计算机系'),
('9512102','刘晨','男','20','计算机系'),
('9512103','王敏','女','20','计算机系'),
('9521101','张立','男','22','信息系'),
('9521102','吴宾','女','21','信息系'),
('9521103','张海','男','20','信息系'),
('9531101','钱小平','女','18','数学系'),
('9531102','王大力','男','19','数学系');
########## 插入课程表(Course)相应数据 ##########
insert into course values('C01','计算机文化学','3','1','41'),
('C02','VB','2','3','61'),
('C03','计算机网络','4','7','14'),
('C04','数据库基础','6','6','24'),
('C05','高等数学','8','2','19'),
('C06','数据结构','5','4','55');
########## 插入学生选课表(DBSC)相应数据 ##########
insert into dbsc values('1','9512101','c01','90','必修'),
('2','9512101','c02','86','选修'),
('3','9512101','c06','45','必修'),
('4','9512102','c02','78','选修'),
('5','9512102','c04','66','必修'),
('6','9521102','c01','82','选修'),
('7','9521102','c02','75','选修'),
('8','9521102','c04','92','必修'),
('9','9521102','c05','50','必修'),
('10','9521103','c02','68','选修'),
('11','9521103','c06','56','必修'),
('12','9531101','c01','80','选修'),
('13','9531101','c05','95','必修'),
('14','9531102','c05','85','必修');
########## End ##########
########## 查询表数据 ##########
SELECT * FROM student;
SELECT * FROM course;
SELECT * FROM dbsc;
第2关:简单查询
#********* Begin *********#
echo "
select Sname,Sdept from student where Sdept = '计算机系';
select Sno from dbsc where Grade < 60;
select Sname,Sdept,Sage from student where Sage >= 20 and Sage < 23 and Sdept = '信息系';
select Sno,Grade from dbsc where Cno = 'c02';
select count(*) from student ;
"
#********* End *********#
第3关:进阶查询
#********* Begin *********#
echo "
select Sno,Sname,Ssex,Sage,Sdept from student where Sname LIKE '张%';
select Sname,Ssex,Sdept from student where Sdept = '计算机系' or Sdept = '数学系' or Sdept = '信息系';
select Cno,count(*) from dbsc where istec ='选修' and (cno='c01' or cno ='c02') group by cno;
select Sno from dbsc group by sno having count(*)>3 ;
select Sname,Cno,Grade from dbsc left join student on student.Sno=dbsc.Sno where student.Sdept='计算机系';
"
#********* End *********#
第4关:复杂查询
#********* Begin *********#
echo "
select distinct student.Sno,student.Sname from student left join dbsc on student.Sno = dbsc.Sno where dbsc.istec = '选修';
select Sname,count(*),avg(Grade) from student right join dbsc on student.Sno = dbsc.Sno group by dbsc.Sno ;
select avg(Grade),count(*) from student left join dbsc on student.Sno = dbsc.Sno
group by dbsc.Sno having count(*)>=4;
select Sname,Cno,Grade from student left join dbsc on student.Sno = dbsc.Sno where student.Sdept = '信息系' and dbsc.Cno = 'c02' and istec = '选修';
update dbsc set grade = grade+5 where grade < 60;
"
#********* End *********#
版权声明
本文为[x 心 动]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_45623072/article/details/124149345
边栏推荐
- The difference between underline and dot of golang import package
- How to uninstall easyton
- Codeforces Round #783 (Div. 2) D题解
- JVM的类加载过程
- ArcMap连接 arcgis server
- 坐标转换WGS-84 转 GCJ-02 和 GCJ-02转WGS-84
- 指针数组与数组指针的区分
- C1000k TCP connection upper limit test
- OpenHarmony开源开发者成长计划,寻找改变世界的开源新生力!
- Easy mock local deployment (you need to experience three times in a crowded time. Li Zao will do the same as me. Love is like a festival mock)
猜你喜欢

I just want to leave a note for myself

Command - sudo

MySQL syntax collation (2)

Pdf reference learning notes

Using oes texture + glsurfaceview + JNI to realize player picture processing based on OpenGL es

Prefer composition to inheritance

命令-sudo

Build intelligent garbage classification applet based on Zero

MySQL syntax collation (4)

An algorithm problem was encountered during the interview_ Find the mirrored word pairs in the dictionary
随机推荐
openlayers 5.0 热力图
SQL Server database in clause and exists clause conversion
The difference between underline and dot of golang import package
arcMap 发布切片服务
山大网安靶场实验平台项目-个人记录(五)
Kubernetes入门到精通-KtConnect(全称Kubernetes Toolkit Connect)是一款基于Kubernetes环境用于提高本地测试联调效率的小工具。
Openharmony open source developer growth plan, looking for new open source forces that change the world!
Data analysis learning directory
坐标转换WGS-84 转 GCJ-02 和 GCJ-02转WGS-84
Speculation on the way to realize the smooth drag preview of video editing software
SSDB foundation 1
Go modules daily use
Translation of audio signal processing and coding: Preface
An idea of rendering pipeline based on FBO
[报告] Microsoft :Application of deep learning methods in speech enhancement
5 minutes to achieve wechat cloud applet payment function (including source code)
Codeforces Round #784 (Div. 4)
SSDB Foundation
White screen processing method of fulter startup page
Deep learning -- Summary of Feature Engineering