当前位置:网站首页>MYSQL-GROUP BY 用法 全网最精,通熟易懂的话解释
MYSQL-GROUP BY 用法 全网最精,通熟易懂的话解释
2022-07-30 05:49:00 【大大大大小小】
Group by 普通意思其他文章都有,不做过多描述
直接上例子:
表1:

首先先匹配一下name=zs的结果,如表2显示:
表2:

如果我想统计一下name=zs在各个address中有多少个?
该怎么弄呢?
首先我们应该弄个以address为组而站队的表
select address,count(id) from t1 where name='zs' group by address;
要注意为什么要选择count(id)而不选择count(name)?
因为count(id)在这个表中是唯一的。那group by 是如何处理的呢?
首先对address进行distinct,distinct简单来说就是去重,分组
会生成一下的逻辑表:

为啥说这个是个逻辑表呢?因为mysql中,只能承载一个数据,不能承载多个数据,是不存在的。
如下逻辑表:

结果会显示成:

这一看就不对,一看就出错
所以这让mysql很难办,险些要翻桌子
为了不让mysql翻桌子,我们只能用:count(id) 另辟蹊径,意思是:符合address=tj的id有多少个
结果如图:

结果显而易见。
边栏推荐
- 掌握JESD204B(三)–AD6676的调试
- Test Development Engineer Growth Diary 007 - Bug Priority Definition and Filling Specifications
- ThreeJS导入外部obj和mtl
- 掌握JESD204B(一)–AD6676的调试
- libgrape-lite: 提供 GraphScope 的图分析能力
- Redis6的数据类型
- DADPS-生物素-炔基_CAS:2241685-22-1试剂反应原理
- wsl2设置静态ip(固定ip)static ip
- OP 代币和不可转让的 NFT 致力于建立新的数字民主
- 从安装到编译: 10分钟教你在本地使用和开发GraphScope
猜你喜欢

Network Protocol 03 - Routing and NAT

How to save modelsim simulation data as a file

Biotin-Dadps-azide|CAS:1260247-50-4|生物素-DADPS-叠氮

04-packing and unpacking

如何使用xilinx的FFT ip

Application of graph computing in network security analysis

Rapidly develop GraphScope graph analysis applications

基于 JupyterLab 插件在 GraphScope 中交互式构图

GAIA-IR:GraphScope 上的并行化图查询引擎

图扑数字孪生北京故宫,推进旅游业元宇宙进程
随机推荐
kubernetes搭建SonarQube进行代码扫描
软件测试术语 - 场景测试
Interactively compose graphs in GraphScope based on the JupyterLab plugin
Mastering JESD204B (1) – Debugging of AD6676
掌握JESD204B(二)–AD6676的调试
测试开发工程师成长日记017 - bug的生命周期
测开基础知识01
作为测试leader,考察求职者的几个方面
藏不住了,我要揭露云原生的那些不好
测试开发工程师成长日记009 - 环境排排站:开发环境、测试环境、生产环境、UAT环境、仿真环境
Redis6的数据类型
从 Vertex 到 Subgraph 再到 PIE: 并行图计算编程模型概览
掌握JESD204B(三)–AD6676的调试
prometheus-federation-tls加密
mysql常用命令以及mysqldump备份
BlockingQueue详细介绍
How to import matlab data into modelsim simulation
Test the basics 01
Test Development Engineer Growth Diary 017 - The Life Cycle of a Bug
Dachang's annual salary of 50w+ recruits test engineers with test platform development capabilities