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;

今天,你学习了吗?

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

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

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

相关推荐
2501_914245931 小时前
CSS如何处理CSS变量作用域冲突_利用特定类名重写变量值
jvm·数据库·python
maqr_1102 小时前
MySQL数据库迁移到云端如何保障安全_数据加密与SSL连接配置
jvm·数据库·python
u0109147602 小时前
MySQL如何限制触发器递归调用的深度_防止触发器死循环方法
jvm·数据库·python
weixin_381288182 小时前
MySQL中如何使用HEX函数转换十六进制_MySQL进制转换函数
jvm·数据库·python
Deitymoon2 小时前
嵌入式数据库——SQLite基础
数据库·sqlite
YMatrix 官方技术社区2 小时前
美国·硅谷|YMatrix 即将亮相 Postgres Conference 2026,前瞻 AI 时代的数据基座
数据库·数据仓库·postgresql·时序数据库·ymatrix
bKYP953cL2 小时前
构建自己的AI编程助手:基于RAG的上下文感知实现方案
数据库·人工智能·ai编程
Bert.Cai3 小时前
MySQL DML简介
数据库·mysql
maqr_1103 小时前
HTML怎么生成订单预览_HTML只读订单信息结构【操作】
jvm·数据库·python
2301_803875613 小时前
如何通过phpMyAdmin给WordPress所有用户发送全站通知_系统表插入
jvm·数据库·python