当前位置:网站首页>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 会将数据全部查询出来,如果一张表数据量比较大 ,此时 容易爆炸,所以真正开发的时候,都是只查一部分数据,所以都是进行分页操作的。

边栏推荐
- insight! Baidu pushed redis ceiling notes, which was originally understood by the database
- What skills do you need to master when learning software testing zero foundation?
- USB type-C details
- solidity转账函数的实现(基于transfer)
- 实验楼----PHP大法
- Go并发详解之一
- GO exe生成图标版本信息
- Six countries in Europe and the United States launched an express line product to optimize the "end-to-end" performance service on the 5th
- Modifier modifier modifier of solidity _;
- Mongodb initialization operation
猜你喜欢

GIS数据漫谈(六)— 投影坐标系统

Cloud container and cloud native

Seven steps, in-depth interpretation of data meaning

LeetCode_63_不同路径Ⅱ

深圳线下报名|StarRocks on AWS:如何对实时数仓进行极速统一分析

Composition and principle of vector network analyzer (vector network)

欧美六国最快5日达 菜鸟推出快线产品 优化“端到端”履约服务

Six countries in Europe and the United States launched an express line product to optimize the "end-to-end" performance service on the 5th

Performance parameters of spectrum analyzer

Wired: who owns the art of the future? Openai allows dall-e users to commercialize their works. At present
随机推荐
Summer Challenge [FFH] JS custom component: DIY a keyboard that can be used at any time! (I)
高德地图实现自定义小蓝点 自定义点标记 绘制多边形/圆形区域 根据地图的移动显示或者隐藏自定义点标记的相关实现
直播|StarRocks 技术内幕 :低基数全局字典优化
insight! Baidu pushed redis ceiling notes, which was originally understood by the database
haproxy实现代理配置
欧美六国最快5日达 菜鸟推出快线产品 优化“端到端”履约服务
记录自己在厦门两年来的面试经历--完结篇
ERROR 2003 (HY000) Can‘t connect to MySQL server on ‘localhost3306‘ (10061)解决办法
UE5 GAS 学习笔记0.2配置插件
Go's sleep
Experimental building - PHP Dafa
Live broadcast starrocks technology insider: low base global dictionary optimization
Ue5 gas learning notes 1.7 task ability tasks
NDK 系列(5):JNI 从入门到实践,爆肝万字详解!
数字化洪流 :企业转型中的资源重组与战略冲突
Brief introduction: basic principle of srv6
Implementation of solid transfer function (based on transfer)
MySQL operation Encyclopedia
Brief introduction to the principle of spectrometer I
iptables防火墙端口规则配置