Mysql配套测试之查询篇

🏝️专栏:Mysql_猫咪-9527的博客-CSDN博客

🌅主页:猫咪-9527-CSDN博客

"欲穷千里目,更上一层楼。会当凌绝顶,一览众山小。"

目录

条件查询简单测试:

1.查询英语成绩不及格的同学(<60)

2.语文成绩在[80,90]分的同学

3.数学成绩是58或者59或者98或者99的同学及数学成绩

4.孙某同学

5.姓孙的同学

6.语文成绩好于英语成绩的同学

7.总分在两百分一下的同学

8.语文成绩大于80且不姓孙的同学

[9.孙某同学,否者要求总成绩>200并且 语文成绩<数学成绩并且英语成绩>80](#9.孙某同学,否者要求总成绩>200并且 语文成绩<数学成绩并且英语成绩>80)

10.null查询(测试表里面并没有null数据想测试,记得插入)

排序查询简单测试:

11.查询所有同学及成绩并按数学升序排序

12.查询同学各门成绩,依次按数学降序,英语升序,语文升序来显示

13.查询同学各门成绩,并按总分排序

14.查询姓孙或者姓曹的同学的数学成绩,并按数学成绩降序排列


测试准备:

(1)创建一个测试数据库

复制代码
create databate text_3_22;

(2)进入数据库

复制代码
use text_3_22;

(3)创建表并插入数据(我已经为你们准备好了,记得插入后再进行测试)

复制代码
-- 创建表结构
create table exam_result (
  id int unsigned primary key auto_increment,
  name varchar(20) not null comment '同学姓名',
  chinese float default 0.0 comment '语文成绩',
  math float default 0.0 comment '数学成绩',
  english float default 0.0 comment '英语成绩'
);

-- 插入测试数据
insert into exam_result (name, chinese, math, english) values
('唐三藏', 67, 98, 56),
('孙悟空', 87, 78, 77),
('猪悟能', 88, 98, 90),
('曹孟德', 82, 84, 67),
('刘玄德', 55, 85, 45),
('孙权', 70, 73, 78),
('宋公明', 75, 65, 30);

(4)记得检验自己插入的数据是否正确

复制代码
select *from exam_result;
条件查询简单测试:
1.查询英语成绩不及格的同学(<60)
复制代码
select name 姓名 ,english 英语 from exam_result where english<60;
2.语文成绩在[80,90]分的同学

方案一:

复制代码
select name 姓名, chinese 语文 from exam_result where chinese>=80 AND chinese<=90;

方案二:

复制代码
select name 姓名, chinese 语文 from exam_result where chinese between 80 and 90;
3.数学成绩是58或者59或者98或者99的同学及数学成绩

方案一:

复制代码
select name 名字,math 数学 from exam_result where math =99 or math =98
or math =59 or math =58;

方案二:

复制代码
select name 姓名, math 数学 from exam_result where math in (98,99,59,58);
4.孙某同学
复制代码
select name 姓名 from exam_result where name like '孙_';
5.姓孙的同学
复制代码
select name 姓名 from exam_result where name like '孙%';
6.语文成绩好于英语成绩的同学
复制代码
select name 姓名,chinese 语文 ,english 英语 from exam_result 
where chinese > english;
7.总分在两百分一下的同学
复制代码
select name,math,english,chinese from exam_result
where math+english+chinese<200;
8.语文成绩大于80且不姓孙的同学
复制代码
select name 姓名 ,chinese 语文 from exam_result 
where chinese>80 and name not like '孙%';
9.孙某同学,否者要求总成绩>200并且 语文成绩<数学成绩并且英语成绩>80
复制代码
select name 姓名,chinese 语文,math 数学,english 英语
from exam_result where name like '孙%' or
( chinese+math+english>200 and chinese<math and english>80);
10.null查询(测试表里面并没有null数据想测试,记得插入)
复制代码
select name,math from exam_result where math<=>null;
排序查询简单测试:
11.查询所有同学及成绩并按数学升序排序
复制代码
select name ,chinese,english,math from exam_result order by math asc;
12.查询同学各门成绩,依次按数学降序,英语升序,语文升序来显示
复制代码
select name,chinese,english,math from exam_result
order by math desc,chinese asc,english asc;
13.查询同学各门成绩,并按总分排序
复制代码
select name ,math +english+chinese total from exam_result 
order by total desc;
14.查询姓孙或者姓曹的同学的数学成绩,并按数学成绩降序排列
复制代码
select name ,math from exam_result
where name like'孙%' or name like '曹%' order by math desc;
15.去重查询练习
复制代码
create table distinct_text(name varchar);
----创建去重测试表结构

insert distinct_text ('a'), ('a'), ('a'), ('a'),('b'),('b'),('b'),('b');

select distinct *from distinct_text;

今天,你学习了吗?

看到这里不容易,点个关注不迷路 !

大家可以在评论区分享一下测试的怎么样!

祝大家学习快乐!每一天。

相关推荐
cookqq9 分钟前
mongodb源码分析session异步接受asyncSourceMessage()客户端流变Message对象
数据库·sql·mongodb·nosql
呼拉拉呼拉21 分钟前
Redis故障转移
数据库·redis·缓存·高可用架构
什么都想学的阿超24 分钟前
【Redis系列 04】Redis高可用架构实战:主从复制与哨兵模式从零到生产
数据库·redis·架构
pp-周子晗(努力赶上课程进度版)44 分钟前
【MySQL】视图、用户管理、MySQL使用C\C++连接
数据库·mysql
斯特凡今天也很帅1 小时前
clickhouse常用语句汇总——持续更新中
数据库·sql·clickhouse
超级小忍2 小时前
如何配置 MySQL 允许远程连接
数据库·mysql·adb
吹牛不交税2 小时前
sqlsugar WhereIF条件的大于等于和等于查出来的坑
数据库·mysql
hshpy3 小时前
setting up Activiti BPMN Workflow Engine with Spring Boot
数据库·spring boot·后端
文牧之4 小时前
Oracle 审计参数:AUDIT_TRAIL 和 AUDIT_SYS_OPERATIONS
运维·数据库·oracle
篱笆院的狗4 小时前
如何使用 Redis 快速实现布隆过滤器?
数据库·redis·缓存