最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Mysql配套测试之查询篇

网站源码admin6浏览0评论

Mysql配套测试之查询篇

测试准备:

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

代码语言:javascript代码运行次数:0运行复制
create databate text_3_22;

(2)进入数据库

代码语言:javascript代码运行次数:0运行复制
use text_3_22;

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

代码语言:javascript代码运行次数:0运行复制
-- 创建表结构
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)记得检验自己插入的数据是否正确

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

方案一:

代码语言:javascript代码运行次数:0运行复制
select name 姓名, chinese 语文 from exam_result where chinese>=80 AND chinese<=90;

方案二:

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

方案一:

代码语言:javascript代码运行次数:0运行复制
select name 名字,math 数学 from exam_result where math =99 or math =98
or math =59 or math =58;

方案二:

代码语言:javascript代码运行次数:0运行复制
select name 姓名, math 数学 from exam_result where math in (98,99,59,58);
4.孙某同学
代码语言:javascript代码运行次数:0运行复制
select name 姓名 from exam_result where name like '孙_';
5.姓孙的同学
代码语言:javascript代码运行次数:0运行复制
select name 姓名 from exam_result where name like '孙%';
6.语文成绩好于英语成绩的同学
代码语言:javascript代码运行次数:0运行复制
select name 姓名,chinese 语文 ,english 英语 from exam_result 
where chinese > english;
7.总分在两百分一下的同学
代码语言:javascript代码运行次数:0运行复制
select name,math,english,chinese from exam_result
where math+english+chinese<200;
8.语文成绩大于80且不姓孙的同学
代码语言:javascript代码运行次数:0运行复制
select name 姓名 ,chinese 语文 from exam_result 
where chinese>80 and name not like '孙%';
9.孙某同学,否者要求总成绩>200并且 语文成绩<数学成绩并且英语成绩>80
代码语言:javascript代码运行次数:0运行复制
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数据想测试,记得插入)
代码语言:javascript代码运行次数:0运行复制
select name,math from exam_result where math<=>null;
排序查询简单测试:
11.查询所有同学及成绩并按数学升序排序
代码语言:javascript代码运行次数:0运行复制
select name ,chinese,english,math from exam_result order by math asc;
12.查询同学各门成绩,依次按数学降序,英语升序,语文升序来显示
代码语言:javascript代码运行次数:0运行复制
select name,chinese,english,math from exam_result
order by math desc,chinese asc,english asc;
13.查询同学各门成绩,并按总分排序
代码语言:javascript代码运行次数:0运行复制
select name ,math +english+chinese total from exam_result 
order by total desc;
14.查询姓孙或者姓曹的同学的数学成绩,并按数学成绩降序排列
代码语言:javascript代码运行次数:0运行复制
select name ,math from exam_result
where name like'孙%' or name like '曹%' order by math desc;
15.去重查询练习
代码语言:javascript代码运行次数:0运行复制
create table distinct_text(name varchar);
----创建去重测试表结构
代码语言:javascript代码运行次数:0运行复制
insert distinct_text ('a'), ('a'), ('a'), ('a'),('b'),('b'),('b'),('b');
代码语言:javascript代码运行次数:0运行复制
select distinct *from distinct_text;
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。 原始发表:2025-03-23,如有侵权请联系 cloudcommunity@tencent 删除数学mysql测试排序数据

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论