Mysql学习笔记(查询语句练习题1)
表格详情:
student表:
teacher表:
course表:
score表:
Mysql查询语句练习:
1.查询Student表中的所有记录的Sname、Ssex和Class列
select sname,ssex,class from student;
2.查询教师所有的单位即不重复的Depart列
select distinct(depart) from teacher;
3.查询Student表的所有记录
select * from student;
4.查询Score表中成绩在60到80之间的所有记录
select * from score where degree between 60 and 80;
select * from score where degree > 60 and degree < 80;
5.查询Score表中成绩为85,86或88的记录
select * from score where degree in (85,86,88);
6.查询Student表中“95031”班或性别为“女”的同学记录
select * from student where class="95031" or ssex="女";
7.以Class降序查询Student表的所有记录
select * from student order by class desc;
8.以Cno升序、Degree降序查询Score表的所有记录
select * from score order by cno asc,degree desc;
9.查询“95031”班的学生人数
select count(sno) from student where class = "95031";
10.查询Score表中的最高分的学生学号和课程号,子查询
select sno,cno from score where degree = (select max(degree) from score);
select sno,cno from score order by degree desc limit 0,1;
11.查询‘3-105’号课程的平均分
select cno,avg(degree) from score where cno="3-105";
12.查询Score表中至少有5名学生选修的并以3开头的课程的平均分数
select cno,avg(degree) from score where cno like '3%' group by cno having count(cno) >= 5;
13.查询每个学生最低分大于70,最高分小于90的Sno列
select sno from score group by sno having min(degree)>70 and max(degree)<90;
14.查询所有学生的Sname、Cno和Degree列
select A.sname,B.cno,B.degree from student A,score B where A.sno=B.sno;
15.查询所有学生的Sno、Cname和Degree列
select A.sno,B.cname,A.degree from score A,course B where A.cno=B.cno;
16.查询所有学生的Sname、Cname和Degree列
select A.sname,B.cname,C.degree from student A join (course B,score C) on A.sno=C.sno and B.cno=C.cno;
17.查询“95033”班所选课程的平均分、课程号
select cno,avg(degree) from score where sno in (select sno from student where class="95033") group by cno;
select A.cno,avg(A.degree) from score A join student B on A.sno=B.sno and B.class="95033" group by A.cno;
18.假设使用如下命令建立了一个grade表
现查询所有同学的Sno、Cno和rank列
select A.sno,A.cno,B.rank from score A,grade B where A.degree between B.low and B.upp;
19.查询选修“3-105”课程且成绩高于“109”号同学成绩的所有同学的记录
select * from score where cno="3-105" and degree > (select degree from score where sno="109" and class="3-105");
select A.* from score as A,score as B where A.cno="3-105" and A.degree>B.degree and B.sno="109" and B.cno="3-105";
20.查询score中选学一门以上课程的同学中分数为非最高分成绩的记录
select * from score where degree<(select max(degree) from score) group by sno having count(sno)>1;
21.查询成绩高于学号为“109”、课程号为“3-105”的成绩的所有记录
select * from score where degree >(select degree from score where sno="109" and cno="3-105");
22.查询和学号为107的同学同年出生的所有学生的Sno、Sname和Sbirthday列
select sno,sname,sbirthday from student where year(sbirthday)=(select year(sbirthday) from student where sno="107");
Mysql学习笔记(查询语句练习题1)相关推荐
- mysql学习笔记(常用语句)
mysql学习总结: 1.启动 mysql -uusername -ppassword 2.切换数据库 use databasename 3.创建数据库 create database name 4. ...
- MySQL学习笔记04-DDL语句学习
目录 07.DDL语句学习 7.1.库和表的管理 库的管理 库的创建:CREATE 库的修改:ALTER 库的删除:DROP 表的管理 表的创建:CREATE 表的修改:ALTER 表的删除:DROP ...
- MySQL学习笔记——基础语句
MySQL默认端口号为3306: 超级用户为root: MySQL常用命令 显示当前服务器版本:select version(); 显示当前日期时间:select now(); 显示当前用户:sele ...
- Mysql学习笔记(基础)基础sql语句详细记录
数据库学习(基础) // 个人网课学习记录,如果有违规等问题,请联系我删除~ mysql下载安装( 解压版安装配置 下载版安装配置 ) 需求分析:使用cmd命令来创建一个数据库,并对数据库中得一张分类 ...
- MySQL学习笔记04【数据库的查询操作、今日内容、表的约束】
MySQL 文档-黑马程序员(腾讯微云):https://share.weiyun.com/RaCdIwas 1-MySQL基础.pdf.2-MySQL约束与设计.pdf.3-MySQL多表查询与事务 ...
- 小白终是踏上了这条不归路----小文的mysql学习笔记(8)----分页查询
** 小白终是踏上了这条不归路----小文的mysql学习笔记(1) 小白终是踏上了这条不归路----小文的mysql学习笔记(2)----条件查询 小白终是踏上了这条不归路----小文的mysql学 ...
- MySQL学习笔记(三)查询
写在前面:本篇为作者自学总结,学习内容为课堂所学和网络学习笔记汇总,对于内容引用部分在文中和文末注明. 文章仅供参考,如需深入了解,请查阅MySQL参考手册.附上下载链接: 链接:https://pa ...
- MySQL学习笔记_上(select查询)
上次整理了一些练习发到博客上了,也说要发基础的,整理了一下午才算是把查询那块的勉强整理完,下次再整理其他的,另外还在写设计模式和数据结构的草稿,写的差不多会慢慢发的,这两项算是副线发展,主线还是按 ...
- MySQL学习笔记(四)——分组函数,分组查询,连接查询
MySQL学习笔记(四)--分组函数,分组查询,连接查询 作者:就叫易易好了 日期:2020/11/18 一.分组函数 功能:用作统计使用,又称为聚合函数或统计函数 分类: sum函数 avg函数 m ...
最新文章
- Webpack中Loader和Plugin的区别和编写思路
- 中国汽车脚垫市场消费趋势与营销渠道分析报告2022版
- mysql varchar char text
- .Net Core应用框架Util介绍(一)
- php新建文件在指定目录下,PHP在获取指定目录下的目录,在获取的目录下面再创建文件,多平台...
- 科研|诺奖得主本庶佑: 不要相信论文里写的东西,《自然》《科学》这些杂志上的观点有九成是不正确的...
- 多么痛的领悟!差不多2015年的时候,我开始关注股票
- paip.提升用户体验---网站导航栏的设计
- matlab pr曲线实例,再理解下ROC曲线和PR曲线 | 丕子
- CV:阿里在CV数据增强领域带来SOTA新范式(已被NeurIPS2022接收)—基于离散化对抗训练的鲁棒视觉新基准!
- PHP函数array_intersect_assoc
- 运算库之numpy(数组的切片操作和数组shape的转换)
- KITTI车辆检测数据集转VOC格式(亲测成功,附KITTI云盘连接以及完整格式转换代码)- KITTI车辆检测数据集看着一篇就够了!
- puppeteer 清空input原本的值
- 教你如何识别DWG文件版本
- 读《技术元素》凯文凯利(Kevin Kelly)
- oracle数据库装载,oracle装载数据库
- 【云原生】SQL(及存储过程)跑得太慢怎么办?
- 用js生成专业个人简历
- WPF DataGrid SelectItem 和 SelectItems的用法