当前位置:网站首页>MYSQL入门与进阶(八)
MYSQL入门与进阶(八)
2022-07-28 17:05:00 【小新爱编程】
目录
1、去重查询
例如:查询有哪些班级

此时查询完成之后 发现有重复数据,我们需要去重
注意 去重尽量少用,例如 我们如果这样操作 有14亿学生 ,此时查询班级,如果去重操作,需要去除的重复太多了。严重影响性能。此时需要从数据库表设计的角度去思考。
2、条件查询 where 语句
2.1、 条件运算符



2.2、多条件查询


2.3、范围查询
例如 年龄 19-25 之间的学生



2.4、模糊查询 like


通配符 有 _ (匹配以为) 和 % (匹配0或者多位)




3、排序操作 order by
我们现在的查询 默认按照id的从小到大进行显示
如果我想按照年龄从小到大进行显示可不可以呢? 可以的 需要使用 order by



有的时候 我们需要定制多排序规则
例如: 先按照年龄的升序排序 如果年龄一样则按照id的降序排序

4、聚合函数 和 分组查询
4.1、 聚合函数
就是对同一列的数据进行统计





MAX MIN AVG SUM COUNT
4.2、分组 group by 列名
聚合函数默认是整表的所有数据进行统计,分组相当于是将整表分组之后 每组中进行统计。
例如 : 查询所有班的最大年龄
查询每个班的最大年龄
Group by 是将 某一列 相同数据的行当成一组

查询 男生 和 女生的数量

分组的条件限定,注意分组查询添加条件 是使用 having
例如 : 查询 人数在2个以上的班级的平均年龄
5、 分页查询 limit
每次我们直接 select * from t_people 会将数据全部查询出来,如果一张表数据量比较大 ,此时 容易爆炸,所以真正开发的时候,都是只查一部分数据,所以都是进行分页操作的。

边栏推荐
- 从 SRE 看 DevOps 建设
- 冒泡排序和相关视频
- Tencent Tang Daosheng: open source is a new mode of production and collaboration in the era of industrial Internet
- UE5 GAS 学习笔记 1.10 预测(Prediction)
- Introduction to CC cable of USB type-C
- "Cloud strategy" will become an important pillar of enterprise digital transformation
- Golang 并发之锁
- LeetCode79题 方法一:深度搜索
- There is a special cryptology language called asn.1
- Composition and principle of vector network analyzer (vector network)
猜你喜欢

多线程与高并发—— 源码解析 AQS 原理

MySQL index usage and optimization

Brief introduction to the principle of spectrometer I

Brief introduction: basic principle of srv6

NDK series (5): from introduction to practice, JNI explodes the liver and explains everything in detail!

What role does low code play in the digital transformation?

DC-DC switching power supply

Detailed explanation of network RJ45 interface

连线:谁拥有未来的艺术?OpenAI允许Dall-E用户将作品商用化,目前而言

Detailed explanation of oscilloscope probe
随机推荐
多线程与高并发—— 源码解析 AQS 原理
UE5 GAS 学习笔记0.2配置插件
UE5 GAS 学习笔记 1.4属性集
LeetCode_63_不同路径Ⅱ
TCP/IP详细图解
Ue5 gas learning notes 1.6 skills gameplay ability
How does Xiaobai learn software testing with zero foundation?
当Golang遇到高并发秒杀
Multithreading and high concurrency -- source code analysis AQS principle
GIS数据漫谈(六)— 投影坐标系统
.net WCF WF4.5 状态机、书签与持久化
What is the employment prospect of software testing?
Ue5 gas learning notes 8.0 references
Mongodb create index
ERROR 2003 (HY000) Can‘t connect to MySQL server on ‘localhost3306‘ (10061)解决办法
Is it really realistic that people who have not been exposed to software testing can take up their posts after two months of training?
#夏日挑战赛#【FFH】JS自定义组件:DIY一个随点随用的键盘!(一)
Iptables防火墙详细介绍
Ue5 gas learning notes 1.10 prediction
欧美六国最快5日达 菜鸟推出快线产品 优化“端到端”履约服务