当前位置:网站首页>MySQL - the difference between count (field), count (primary key), count (1), count (*)
MySQL - the difference between count (field), count (primary key), count (1), count (*)
2022-07-29 02:53:00 【Husky who is not eager for power】
List of articles
count( Field )、count( Primary key )、count(1)、count(*) The difference between
- count() It's an aggregate function , Judge the returned result set line by line , If count The field value corresponding to the parameter in the function is not Null, Add... To the cumulative value 1, Otherwise, we will not add , Finally return the cumulative value .
- count(*)、count(1) and count( Primary key id) All return the total number of rows of the result set that meet the conditions ; and count( Field ), Then the value in the returned field is not Null The total number of rows of .
With weibo_user Table as an example , There are 99 Data ,created_at The field value is not Null Data are available. 6 strip
- count(*) Query all data
- count(id) Query all data
- count(1) Query all data
- count(create_at) Query only 6 Data , Values are not for NULL The data of
Execution efficiency
- If the data table has no primary key , that count(1) Than count() fast ;
- If there is a primary key , That's the primary key count It's better than count() Be quick ;
- If the table has only one field ,count(*) It's the fastest .
边栏推荐
- 混淆矩阵学习笔记
- 关于时间复杂度的一些新认识
- Implement encapsulated public method global call in laravel framework
- ECCV 2022 | airdet: a small sample target detection method without fine tuning
- Interpretation of ue4.25 slate source code
- Redis queue realizes second kill
- 看机器人教育引领素质教育主流
- Pytest环境部署+用例执行管理+用例参数化
- OSPF experiment
- idea替换所有文件中的内容
猜你喜欢

每周推荐短视频:如何让产品开发更加有效?

Asemi rectifier bridge s25vb100, s25vb100 parameters, s25vb100 application

TP5.0 小程序用户无需登录,直接获取用户手机号。

etcd实现大规模服务治理应用实战

Analysis of Project-based Learning Creativity in steam Education

并发模式之生产者消费者模式

C语言:空心正方形图案

R语言ERROR: compilation failed for package ‘****‘

Comic algorithm_ Xiaohuihui interview

MongoDB索引 (3)
随机推荐
Analysis of Project-based Learning Creativity in steam Education
Which is a good automatic account distribution system?
看机器人教育引领素质教育主流
Some records during the development of ros2/ros1
The origin of Nacos' name
关于时间复杂度的一些新认识
Flink kernel source code (VII) Flink SQL submission process
11. Writing rules - pseudo target
践踏---离散化+树状数组+差分
PHP lucky draw system with background source code
sqlilabs less-32~less-33
Notes on the sixth day
Mysql复合查询(重要)
6-21 vulnerability exploitation MySQL weak password cracking
Comic algorithm_ Xiaohuihui interview
解析Steam教育中的项目式学习创造力
《微信小程序-进阶篇》Lin-ui组件库源码分析-Button组件(二)
Add a row to a specific location in the dataframe
Pgzero飞机大战
PHP process communication series (I) named pipes




