当前位置:网站首页>MySQL - count(字段)、count(主键)、count(1)、count(*)的区别
MySQL - count(字段)、count(主键)、count(1)、count(*)的区别
2022-07-29 02:27:00 【不渴望力量的哈士奇】
count(字段)、count(主键)、count(1)、count(*)的区别
- count()是一个聚合函数,对于返回的结果集一行行地判断,如果 count 函数中参数对应的字段值不是 Null,累计值就加 1,否则不加,最后返回累计值。
- count(*)、count(1)和count(主键 id) 都返回满足条件的结果集的总行数;而 count(字段),则返回字段中值不为 Null 的总行数。
以weibo_user表为例,表中共有99条数据,created_at字段值不为Null的数据有6条
- count(*)查询到全部数据
- count(id)查询到全部数据
- count(1)查询到全部数据
- count(create_at)只查询到6条数据,值不为NULL的数据
执行效率
- 如果数据表没有主键,那么count(1)比count()快;
- 如果有主键,那主键作为count的条件也比count()要快;
- 如果表只有一个字段,count(*)就是最快的。
边栏推荐
- 这个博主,qt归类比较全,有空去学习总结,记录一下。
- STM32C8T6编码器电机测速与arduino光电模块测速
- C language: hollow square pattern
- This blogger has a comprehensive classification of QT. If you are free, go to study and summarize it and record it.
- 践踏---离散化+树状数组+差分
- 图书管理系统
- What are the TCP retransmission mechanisms?
- 新版海螺影视主题模板M3.1全解密版本多功能苹果CMSv10后台自适应主题开源全解密版
- Double write consistency of MySQL and redis
- Memories of many years ago
猜你喜欢

K210——声源定位、声音识别

混淆矩阵学习笔记

Youxuan software appoints Huang Zhijun as the general manager of the company

Implementation principle of golang synergy

C语言:小乐乐与进制转换

Multimodal Unsupervised Image-to-Image Translation多通道无监督图像翻译

ECCV 2022 | AirDet:无需微调的小样本目标检测方法

New UI Sifang aggregate payment system source code / new usdt withdrawal / latest update security upgrade to fix XSS vulnerability patch vulnerability

Teach you how to install vscode by hand (with illustrated steps)

解析机器人与人类情感共鸣的主观意识
随机推荐
Cloud development pocket toolbox wechat applet source code
双for循环
图书管理系统
nacos名字的由来
HTB-Blocky
Continuous learning / life long learning
Three expiration strategies
白马过隙的时光
etcd实现大规模服务治理应用实战
Multiple inheritance and derived class member identification
Mqtt routine
架构师进阶,微服务设计与治理的 16 条常用原则
常用hooks总结
C语言:小乐乐与欧几里得
一款好看的iapp捐赠榜单源码
QT qstringlist usage
漫画算法_小灰灰面试
ASEMI整流桥S25VB100,S25VB100参数,S25VB100应用
数仓中概念术语解析
laravel框架中实现封装公共方法全局调用




