MySQL数据库_(学生_教师_课程_成绩)表_练习
SQL的执行顺序
(8) SELECT (9) DISTINCT column,... 选择字段、去重
(6) AGG_FUNC(column or expression),... 聚合
(1) FROM [left_table] 选择表
(3) <join_type> JOIN <right_table> 链接
(2) ON <join_condition> 链接条件
(4) WHERE <where_condition> 条件过滤
(5) GROUP BY <group_by_list> 分组
(7) HAVING <having_condition> 分组过滤
(9) ORDER BY <order_by_list> 排序
(10) LIMIT count OFFSET count; 分页
/*==============================================================*/
/* Table: teachers */
/*==============================================================*/
drop table if exists teachers;
create table teachers(tno varchar(3) not null,tname varchar(4),tsex varchar(2),tbirthday datetime,prof varchar(6),depart varchar(10),primary key (tno)
);
/*==============================================================*/
/* Table: students */
/*==============================================================*/
drop table if exists students;
create table students
(sno varchar(3) not null,sname varchar(4) not null,ssex varchar(2) not null,sbirthday datetime,class varchar(5),primary key (sno)
);
/*==============================================================*/
/* Table: courses */
/*==============================================================*/
drop table if exists courses;
create table courses
(cno varchar(5) not null,cname varchar(10) not null,tno varchar(3) not null,primary key (cno)
);
alter table courses add constraint FK_Reference_3 foreign key(tno) references teachers(tno) on delete restrict on update restrict;
/*==============================================================*/
/* Table: scores */
/*==============================================================*/
drop table if exists scores;
create table scores
(sno varchar(3) not null,cno varchar(5) not null,degree numeric(10,1) not null,primary key (sno, cno)
);alter table scores add constraint FK_Reference_1 foreign key(sno) references students(sno) on delete restrict on update restrict;alter table scores add constraint FK_Reference_2 foreign key(cno) references courses(cno) on delete restrict on update restrict;
# 考试题型# 查看一张表中的所有记录(studnets)
select * from students;# 查询一张表中的指定列(students(学号,名字))
select sno,sname from students;# 查询指定的记录(students(学号=101))
select * from students where sno=101;# 模糊查询--查询1976年出生的学生
select * from students where sbirthday like '1976-%'# 模糊查询--查询70后的学生
select * from students where sbirthday like '197%'# 查询某个范围之间的所有记录
select * from students as s where s.sno between 101 and 107;# 查询满足多个条件的记录 and or in
select * from students as s where s.ssex = '男' and s.class ='95033';
select * from students as s where s.sno = 101 or s.sno=103;
select * from students as s where s.class in (95031,95033); # 去重 distinct
select distinct s.class from students as s# 按学号升降 查询记录
select * from students as s order by s.sno asc;
select * from students as s order by s.sno desc;# 查询每个班的人数
select class,count(class) from students group by class;
select stu.class,count(stu.class) from students as stu group by class# 查询学生中最大和最小出生日期与姓名
select stu.sname,stu.sbirthday from students as stuwhere stu.sbirthday = (select max(sbirthday) from students )ORstu.sbirthday = (select min(sbirthday) from students )
# 查询每个课程的评价成绩
select cno,avg(degree) from scoresgroup by cno# 查询男教师及其所上的课程
select * from teachers as a inner join courses as b on a.tno = b.tno and a.tsex='男'# 查询每个老师教的课程
select * from teachers as tleft join courses as con t.tno = c.tno# 查询女老师的信息
select *
from teachers as t
left join courses as c on t.tno = c.tnowhere t.tsex = '女'# 查询得分前3名的学员信息
select *
from students as s where s.sno in (select a.sno from(select sc.snofrom scores as scorder by sc.degreelimit 3 )as a)# 查询课程是“计算机导论”的,得分前3名的学员信息
select *
from scores
where cno = (select cno from courses where cname='计算机导论'
)
order by degree desc limit 3select * from scores where cno='3-105' order by degree limit 3
MySQL数据库_(学生_教师_课程_成绩)表_练习相关推荐
- 计算机及应用成绩表,Excel的基本应用—制作成绩表_计算机软件及应用_IT计.ppt...
Excel的基本应用-制作成绩表_计算机软件及应用_IT计.ppt 第6章 Excel的基本应用-制作成绩表 * * ROUND函数 ROUND函数返回某个数字按指定位数四舍五入后的数字. 语法格式为 ...
- SQL数据库创建学生、教师、选课表
SQL数据库创建学生.教师.选课表 创建学生表 create table student (sno char(14) primary key,sname char (10) not null,ssex ...
- C语言:有N个学生,每个学生有3门课程的成绩,从键盘输入以上数据(包括学号、姓名、3门课程的成绩),计算出平均成绩,将原有数据和计算出的平均成绩存放在磁盘文件stu_list.txt中。
/*有N个学生,每个学生有3门课程的成绩,从键盘输入以上数据(包括学号.姓名.3门课程的成绩),计算出平均成绩,将原有数据和计算出的平均成绩存放在磁盘文件stu_list.txt中.*/ /*以5个学 ...
- 【C语言】#文件操作#有5个学生,每个学生有3门课程的成绩,从键盘输入以上数据(包括学号、姓名、3门课成绩),计算出平均成绩,将原有数据和计算出的平均分数存放在磁盘文件stud中。
题目: (1)有5个学生,每个学生有3门课程的成绩,从键盘输入以上数据(包括学号.姓名.3门课成绩),计算出平均成绩,将原有数据和计算出的平均分数存放在磁盘文件stud中. 设5名学生的学号.姓名和3 ...
- 有2个学生,每个学生有3门课程的成绩,从键盘中输入学生数据(包括学号,姓名 3门课程成绩),计算出平均成绩,将原有数据和计算出的平均分数存放在磁盘文件stud中
有2个学生,每个学生有3门课程的成绩,从键盘中输入学生数据(包括学号,姓名3门课程成绩),计算出平均成绩,将原有数据和计算出的平均分数存放在磁盘文件stud中 解题思路:看到要输入不同类型的数据,考虑 ...
- 有五个学生,每个学生有3门课程的成绩,从键盘输入学生数据(包括学号、姓名、3门课程成绩),计算出平均成绩,将原有的数据和计算出的平均分数存放在磁盘文件stud中。
有五个学生,每个学生有3门课程的成绩,从键盘输入学生数据(包括学号.姓名.3门课程成绩),计算出平均成绩,将原有的数据和计算出的平均分数存放在磁盘文件stud中. #include <stdio ...
- 【C语言入门】已知10个学生的5门课程的成绩,将其存入一个二维数组,求每个学生的总成绩和平均成绩。
题目:已知10个学生的5门课程的成绩,将其存入一个二维数组,求每个学生的总成绩和平均成绩. # include <stdio.h> int main() {int i, j, s = 0, ...
- 显示计算机工程系老师所教课程的成绩表.,sql查询
课程:数据库 设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher). 1.用insert语句写上次所建的数据 INSERT ...
- mysql查询不同老师所教不同课程_mysql数据库面试题(学生表_课程表_成绩表_教师表)...
Student(Sid,Sname,Sage,Ssex)学生表 Sid:学号 Sname:学生姓名 Sage:学生年龄 Ssex:学生性别 Course(Cid,Cname,Tid)课程表 Cid:课 ...
- mysql中 课程1比课程2成绩高_小菜菜mysql练习解读分析1——查询 01 课程比 02 课程成绩高的学生的信息及课程分数...
查询" 01 "课程比" 02 "课程成绩高的学生的信息及课程分数 好的,第一道题,刚开始做,就栽了个跟头,爽歪歪,至于怎么栽跟头的 --需要分析题目,查询的是 ...
最新文章
- 【Scala】Scala-调用Java-集合
- 从SQL Server 2000/2005到SQL Server 2008的升级测试
- 【Python】学习笔记总结6(正则表达式)
- Fiori UI上创建的note和web client UI上note的对应关系
- 【OpenCV 例程200篇】79. 频率域图像滤波的基本步骤
- IT凭什么拿高薪?!
- android shape 3d效果,如何绘制SuperShape3D作为网格?
- 用Redis实现分布式锁 与 实现任务队列
- 20200703每日一句
- 影子系统、沙盒、虚拟机的区别
- adb 连接手机 cannot connect to xxx.xxx.x.xx:5555: 由于目标计算机积极拒绝,无法连接。 (10061)
- matlab标注图例位置,MATLAB中标注图例
- 一步一步理解CPU芯片漏洞:Meltdown与Spectre
- [C/C++]宽字符与控制台程序
- Java生成纳秒时间戳
- kpw4换壁纸_kindle 篇五:kindle paperwhite4使用30天总结
- 我发的文章变成了0和1,那0和1是怎么发送给你的?计算机网络(二)物理层
- 数值计算 - 误差的来源
- win11关闭用户账户控制方法
- js显示格式化代码并高亮(vue中实现代码高亮)