当前位置:网站首页>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有多少个
结果如图:

结果显而易见。
边栏推荐
- 快速开发 GraphScope 图分析应用
- 读取GZ包的内容代码
- Waterfall flow (custom layout implementation)
- npm安装nodejs环境配置
- Dachang's annual salary of 50w+ recruits test engineers with test platform development capabilities
- 使用Apifox测试套件自动化测试接口
- About memcache kernel, so one of the most popular
- 关于memcache内核,全网最通俗的讲解
- matlab机器学习_01
- OP tokens and non-transferable NFTs work to build a new digital democracy
猜你喜欢

Graph Computing 101: Types, Languages, and Systems of Graph Computing

Interactively compose graphs in GraphScope based on the JupyterLab plugin

【JVM】线上应用故障排查

使用Apifox测试套件自动化测试接口

图计算101:图计算的类型、语言与系统

libgrape-lite on GPUs: GPU helps accelerate graph analysis tasks

一种新的DNA生物素系统Biotin LC hydrazide|CAS:109276-34-8|(+)-生物素酰胺基己酸肼

matlab机器学习_01

Advanced multi-threading (lock strategy, spin+CAS, Synchronized, JUC, semaphore)

Application of graph computing in network security analysis
随机推荐
Test Development Engineer Growth Diary 003 - Interface Automation Framework Construction
删除openstack中的僵尸实例
THREEJS导入外部OBJ+MTL后内存优化
Mastering JESD204B (2) – Debugging of AD6676
替换xxx.jar的class文件命令
PC DBCO-PEG3-Biotin|PC-生物素-PEG3-DBCO可用于使用无铜点击化学
Test Development Engineer Growth Diary 018 - Record of Required Questions for Test Interview (Continuous Update)
SE_01
Deploy GraphScope with Helm
prometheus监控minio
网络协议04 - 物理层和数据链路层
Advanced multi-threading (lock strategy, spin+CAS, Synchronized, JUC, semaphore)
Test Development Engineer Growth Diary 007 - Bug Priority Definition and Filling Specifications
基于THREEJS场景中模型局部辉光效果
Biotin-PEG4-SS-Alkyne_1260247-54-8_生物素-PEG4-SS-炔烃
多线程基础(概念,创建,中断)
网络协议03 - 路由和NAT
Mastering JESD204B (3) – Debugging of AD6676
网络协议01 - 基础概念
MongoDB - Introduction, Data Types, Basic Statements