SQL练习2.3

建表

# 学生表
create table t_student
(stu_id   varchar(10),stu_name varchar(10),stu_age  datetime,stu_sex  varchar(10)
);# 课程表
create table t_t_course
(c_id    varchar(10),c_name  varchar(10),c_teaid varchar(10)
);# 教师表
create table t_t_teacher
(tea_id   varchar(10),tea_name varchar(10)
);# 成绩表
create table t_t_score
(s_stuid varchar(10),s_cid   varchar(10),s_score decimal(18, 1)
);-- 向t_student表插入数据
insert into t_student(stu_id, stu_name, stu_age, stu_sex)
values ('01', '赵雷', '1990-01-01', '男');
insert into t_student(stu_id, stu_name, stu_age, stu_sex)
values ('02', '钱电', '1990-12-21', '男');
insert into t_student(stu_id, stu_name, stu_age, stu_sex)
values ('03', '孙风', '1990-12-20', '男');
insert into t_student(stu_id, stu_name, stu_age, stu_sex)
values ('04', '李云', '1990-12-06', '男');
insert into t_student(stu_id, stu_name, stu_age, stu_sex)
values ('05', '周梅', '1991-12-01', '女');
insert into t_student(stu_id, stu_name, stu_age, stu_sex)
values ('06', '吴兰', '1992-01-01', '女');
insert into t_student(stu_id, stu_name, stu_age, stu_sex)
values ('07', '郑竹', '1989-01-01', '女');
insert into t_student(stu_id, stu_name, stu_age, stu_sex)
values ('09', '张三', '2017-12-20', '女');
insert into t_student(stu_id, stu_name, stu_age, stu_sex)
values ('10', '李四', '2017-12-25', '女');
insert into t_student(stu_id, stu_name, stu_age, stu_sex)
values ('11', '李四', '2012-06-06', '女');
insert into t_student(stu_id, stu_name, stu_age, stu_sex)
values ('12', '赵六', '2013-06-13', '女');
insert into t_student(stu_id, stu_name, stu_age, stu_sex)
values ('13', '孙七', '2014-06-01', '女');-- 向t_t_course表插入数据
insert into t_t_course(c_id, c_name, c_teaid)
values ('01', '语文', '02');
insert into t_course(c_id, c_name, c_teaid)
values ('02', '数学', '01');
insert into t_course(c_id, c_name, c_teaid)
values ('03', '英语', '03');-- 向t_t_teacher表插入数据
insert into t_teacher(tea_id, tea_name)
values ('01', '张三');
insert into t_teacher(tea_id, tea_name)
values ('02', '李四');
insert into t_teacher(tea_id, tea_name)
values ('03', '王五');-- 向t_t_score表插入数据
insert into t_score(s_stuid, s_cid, s_score)
values ('01', '01', 80);
insert into t_score(s_stuid, s_cid, s_score)
values ('01', '02', 90);
insert into t_score(s_stuid, s_cid, s_score)
values ('01', '03', 99);
insert into t_score(s_stuid, s_cid, s_score)
values ('02', '01', 70);
insert into t_score(s_stuid, s_cid, s_score)
values ('02', '02', 60);
insert into t_score(s_stuid, s_cid, s_score)
values ('02', '03', 80);
insert into t_score(s_stuid, s_cid, s_score)
values ('03', '01', 80);
insert into t_score(s_stuid, s_cid, s_score)
values ('03', '02', 80);
insert into t_score(s_stuid, s_cid, s_score)
values ('03', '03', 80);
insert into t_score(s_stuid, s_cid, s_score)
values ('04', '01', 50);
insert into t_score(s_stuid, s_cid, s_score)
values ('04', '02', 30);
insert into t_score(s_stuid, s_cid, s_score)
values ('04', '03', 20);
insert into t_score(s_stuid, s_cid, s_score)
values ('05', '01', 76);
insert into t_score(s_stuid, s_cid, s_score)
values ('05', '02', 87);
insert into t_score(s_stuid, s_cid, s_score)
values ('06', '01', 31);
insert into t_score(s_stuid, s_cid, s_score)
values ('06', '03', 34);
insert into t_score(s_stuid, s_cid, s_score)
values ('07', '02', 89);
insert into t_score(s_stuid, s_cid, s_score)
values ('07', '03', 98);
练习
#17.查询学过编号为"02"但没有学过编号为"01"课程的学生信息和相关课程成绩
select *
from t_student sinner join t_score sc on s.stu_id = sc.s_stuid
where s.stu_id in (select sc1.s_stuid from t_score sc1 where sc1.s_cid = 02)and s.stu_id not in (select sc2.s_stuid from t_score sc2 where sc2.s_cid = 01);#18. 查询同时选修了"01"课程和"02"课程的学生信息及相关课程成绩
select *
from t_student s
where s.stu_id in (select sc1.s_stuid from t_score sc1 where sc1.s_cid = 02)and s.stu_id in (select sc2.s_stuid from t_score sc2 where sc2.s_cid = 01);#19. 查询选修了"01"课程但可能没有选修"02"课程的学生信息及相关课程成绩(不存在时显示为0)
select *
from t_student sinner join t_score sc on s.stu_id = sc.s_stuid
where s.stu_id not in (select sc1.s_stuid from t_score sc1 where sc1.s_cid = 02)and s.stu_id in (select sc2.s_stuid from t_score sc2 where sc2.s_cid = 01);#20. 查询平均成绩大于等于 60 分的同学的学生编号和学生姓名和平均成绩(成绩保留2位小数)
select round(avg(sc.s_score), 2), s.stu_name, s.stu_id
from t_student sinner join t_score sc on s.stu_id = sc.s_stuid
group by s.stu_name, s.stu_id
having avg(sc.s_score >= 60);#21. 查询所有同学的学生编号、学生姓名、选课总数、所有课程的成绩总和** (没有选课的学生显示为0)
select s.stu_id, s.stu_name, COUNT(sc.s_score), sum(sc.s_score)
from t_student sinner join t_score sc on s.stu_id = sc.s_stuid
group by s.stu_id, s.stu_name;#22. 查询学过「张三」老师授课的同学的信息
select distinct s.*
from t_student sinner join t_score sc on s.stu_id = s.stu_idinner join t_course co on sc.s_cid = co.c_idinner join t_teacher t on co.c_teaid = t.tea_id
where t.tea_name = '张三' order by s.stu_id;#23. 查询没有学全所有课程的同学的信息
select s.stu_id,s.stu_name,count(sc.s_score) from t_student s inner join t_score sc on s.stu_id = sc.s_stuid inner join t_course co on sc.s_cid = co.c_id group by s.stu_id,stu_name having count(sc.s_score) != 3;#24. 查询至少有一门课与学号为"01"的同学所学相同的同学的信息(不含学号为"01"的学生)
select distinct s.* from t_student s inner join t_score sc on s.stu_id = sc.s_stuid where sc.s_cid in (select sc1.s_cid from t_score sc1 where sc1.s_stuid = 01);

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/14376.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

nginx 动静分离、gzip压缩、负载均衡、root/alias

在Nginx中,动静分离、gzip压缩、负载均衡以及root和alias指令是常见的配置和优化点。下面我将分别解释这些概念和如何配置它们。 动静分离 动静分离是指将动态请求和静态请求分开处理,由不同的服务器或Nginx的不同位置来处理。这样可以提高网站的性能和…

SpringBoot 启动报错,EnableConfigurationProperties 注解跳坑记

使用SpringBoot 脚手架搭建的一个简单的 web demo ,开启了属性自动注入,配置文件如下: Setter Getter Configuration ConfigurationProperties(prefix "com.ff") EnableConfigurationProperties(FFProperties.class) public clas…

今日刷三题(day14):ISBN号码+kotori和迷宫+矩阵最长递增路径

题目一:ISBN号码 题目描述: 每一本正式出版的图书都有一个ISBN号码与之对应,ISBN码包括9位数字、1位识别码和3位分隔符,其规定格式如“x-xxx-xxxxx-x”,其中符号“-”是分隔符(键盘上的减号)&…

STM32使用旋转编码开关

一、旋转编码开关如何工作 编码器内部有一个开槽圆盘,连接到公共接地引脚 C。它还具有两个接触针 A 和 B,如下所示。 当您转动旋钮时,A 和 B 按照特定顺序与公共接地引脚 C 接触,具体顺序取决于转动旋钮的方向。 当它们与公共地接…

在 package.json 文件中,版本号前的 ^ 符号含义

在 package.json 文件中,版本号前的 ^ 符号有特定的含义,它控制了包依赖的版本范围。 具体来说,^ 符号表示兼容性范围符号,允许安装与指定版本兼容的更新版本。 例如,“vue”: “^3.0.0” 意味着: 可以安…

Web3 游戏平台 Creo Engine 销毁代币总量的20%,以促进长远发展

Creo Engine 5月16日进行了第三次代币销毁,这次的销毁占代币总量的 20%。一共销毁了2亿 $CERO 代币,市场价值接近 2000 万美元。 Creo Engine 致力于连接世界、为玩家提供一站式游戏中心,并提升 Web3 游戏体验。 Creo Engine 发布于2022年&am…

USB抓包工具:bushound安装及使用

一、环境搭建 下载busbound6.01安装包,安装完成,重启电脑。 二、工具配置 按照下图配置工具: 使能自动识别新设备 2. 设置抓取数据的容量 三、抓包 回到capture选项卡,在页面的右下角有个run的按钮,点击使能&…

RedHat9 | 磁盘管理

硬盘分区类型 MBR分区方案 MBR也被称为主引导记录,它存在0柱面0磁道0扇区内,在磁盘的第一个扇区内,大小为512字节 512字节包含:446字节初始化程序加载器、64字节分区表、2字节校验码由于每个分区为16字节,所以MBR只…

Git配置详解

天行健,君子以自强不息;地势坤,君子以厚德载物。 每个人都有惰性,但不断学习是好好生活的根本,共勉! 文章均为学习整理笔记,分享记录为主,如有错误请指正,共同学习进步。…

js实现元素根据鼠标滚轮滚动向左右上下滑动着从模糊到清楚显示出来

html代码 <div ref{test} id"animatedElement" className"not-animated"> <div style{{width:"100px",height:"50px",backgroundColor:"red"}}> </div> </div> JS代码 const te…

用智能插件(Fitten Code: Faster and Better AI Assistant)修改好了可以持久保存的vue3留言板

天际 第一修改是选项式&#xff1a; <!-- 模板结构 --> <template><div><textarea placeholder"请输入备注内容" v-model"newItem"></textarea><button click"addItem">添加</button><hr><…

Vue2+Element 封装评论+表情功能

有需要的小伙伴直接拿代码即可&#xff0c;不需要下载依赖&#xff0c;目前是初始版本&#xff0c;后期会进行代码的优化。 评论组件如下&#xff1a; 创建 comment.vue 文件。 表情组件 VueEmoji.vue 在评论组件中使用。 <template><div class"comment"…

《主对角线求和》

描述 有一个n行n列的二维数组&#xff0c;请你求出二维数组的主对角线上的所有数字的和是多少。 输入描述 第一行一个整数n&#xff0c;代表下面输入的是n行n列(2≤n≤10)的二维数组&#xff1b; 接下来n行&#xff0c;每行n列&#xff0c;表示二维数组的每个元素各是多少。 …

数字孪生技术在管理中有哪些实际应用?

随着科学技术的不断提高&#xff0c;数字孪生技术也在不断的从理论应用至现实&#xff0c;并且涉及领域较为广泛。 在生产运营管理层面&#xff0c;通过构建数字孪生模型&#xff0c;企业可以精准模拟和优化生产线&#xff0c;实现生产流程的智能化和高效化。比如&#xff0c;…

TypeScript-搭建编译环境

搭建编译环境 TypeScript 编写的代码是无法直接在js引擎( 浏览器 / Nodejs )中运行的&#xff0c;最终还需要经过编译成js代码才可以正常运行 搭建手动编译环境 1️⃣ 全局安装 typescript 包&#xff08;编译引擎&#xff09; -> 注册 tsc 命令 npm i -g typescript 2…

下拉框操作/键鼠操作/文件上传

在我们做UI自动化测试的时候&#xff0c;会有一些元素需要特殊操作&#xff0c;比如下拉框操作/键鼠操作/文件上传。 下拉框操作 在我们很多页面里有下拉框的选择&#xff0c;这种元素怎么定位呢&#xff1f;下拉框分为两种类型&#xff1a;我们分别针对这两种元素进行定位和…

2024最新 Jenkins + Docker 实战教程(五)- 配置Gitee Webhooks实现自动构建部署

&#x1f604; 19年之后由于某些原因断更了三年&#xff0c;23年重新扬帆起航&#xff0c;推出更多优质博文&#xff0c;希望大家多多支持&#xff5e; &#x1f337; 古之立大事者&#xff0c;不惟有超世之才&#xff0c;亦必有坚忍不拔之志 &#x1f390; 个人CSND主页——Mi…

Packet Tracer-HSRP+DHCPv4+VLAN间路由+以太通道综合实验

实验拓扑&#xff1a; 实验内容&#xff1a; VLAN及VLAN间路由的配置&#xff0c;以太通道的配置&#xff0c;STP的根调整&#xff0c;DHCPv4的配置&#xff0c;首跳冗余HSRP的配置。 实验最终结果&#xff1a; PC可以自动获取到DHCP-Server分配的IP地址&#xff0c;实现首跳…

【Sentinel】Sentinel配置zk持久化

代码 import cn.hutool.core.util.StrUtil; import com.alibaba.csp.sentinel.datasource.ReadableDataSource; import com.alibaba.csp.sentinel.datasource.zookeeper.ZookeeperDataSource; import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule; import com.a…

信息系统工程师--八大绩效域-交付绩效域

信息系统工程师的八大绩效域包括&#xff1a;干系人、团队、开发方法和生命周期、项目工作、规划、交付、度量、不确定性。 预期目标 1、项目有助于实现业务目标和战略 2、项目实现了预期成果 3、在预定时间内实现了项目收益 4、项目团队对需求有清晰的理解 5、干系人接受…