mysql count(*)和count(1)及count(col)的区别测试
来源:互联网 发布:网络大电影发行 编辑:程序博客网 时间:2024/06/05 15:55
----查看表定义
-----插入null值 ,并分别比较count(*)、count(1)和count(col)
(product)root@localhost [test]> insert into tab_t3 values(null,null);
Query OK, 1 row affected (0.00 sec)
(product)root@localhost [test]> show create table tab_t3;
Current database: test
Current database: test
+--------+---------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+--------+---------------------------------------------------------------------------------------------------------------------------------------+
| tab_t3 | CREATE TABLE `tab_t3` (
`c_varchar` varchar(5) DEFAULT NULL,
`c_char` char(5) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+--------+---------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
| Table | Create Table |
+--------+---------------------------------------------------------------------------------------------------------------------------------------+
| tab_t3 | CREATE TABLE `tab_t3` (
`c_varchar` varchar(5) DEFAULT NULL,
`c_char` char(5) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+--------+---------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
----查看表tab_t3的记录
(product)root@localhost [test]> select * from tab_t3;
(product)root@localhost [test]> select * from tab_t3;
+-----------+--------+
| c_varchar | c_char |
+-----------+--------+
| hello | hello |
+-----------+--------+
1 row in set (0.01 sec)
| c_varchar | c_char |
+-----------+--------+
| hello | hello |
+-----------+--------+
1 row in set (0.01 sec)
-----插入''值 ,并分别比较count(*)、count(1)和count(col)
(product)root@localhost [test]> insert into tab_t3 values('','');
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
(product)root@localhost [test]> select * from tab_t3;
+-----------+--------+
| c_varchar | c_char |
+-----------+--------+
| hello | hello |
| | |
+-----------+--------+
2 rows in set (0.00 sec)
+-----------+--------+
| c_varchar | c_char |
+-----------+--------+
| hello | hello |
| | |
+-----------+--------+
2 rows in set (0.00 sec)
(product)root@localhost [test]> select count(*) from tab_t3;
+----------+
| count(*) |
+----------+
| 2 |
+----------+
1 row in set (0.00 sec)
+----------+
| count(*) |
+----------+
| 2 |
+----------+
1 row in set (0.00 sec)
(product)root@localhost [test]> select count(1) from tab_t3;
+----------+
| count(1) |
+----------+
| 2 |
+----------+
1 row in set (0.00 sec)
+----------+
| count(1) |
+----------+
| 2 |
+----------+
1 row in set (0.00 sec)
(product)root@localhost [test]> select count(c_varchar) from tab_t3;
+------------------+
| count(c_varchar) |
+------------------+
| 2 |
+------------------+
1 row in set (0.00 sec)
+------------------+
| count(c_varchar) |
+------------------+
| 2 |
+------------------+
1 row in set (0.00 sec)
-----插入null值 ,并分别比较count(*)、count(1)和count(col)
(product)root@localhost [test]> insert into tab_t3 values(null,null);
Query OK, 1 row affected (0.00 sec)
(product)root@localhost [test]> select count(c_varchar) from tab_t3;
+------------------+
| count(c_varchar) |
+------------------+
| 2 |
+------------------+
1 row in set (0.00 sec)
+------------------+
| count(c_varchar) |
+------------------+
| 2 |
+------------------+
1 row in set (0.00 sec)
(product)root@localhost [test]> select count(*) from tab_t3;
+----------+
| count(*) |
+----------+
| 3 |
+----------+
1 row in set (0.00 sec)
+----------+
| count(*) |
+----------+
| 3 |
+----------+
1 row in set (0.00 sec)
(product)root@localhost [test]> select count(1) from tab_t3;
+----------+
| count(1) |
+----------+
| 3 |
+----------+
1 row in set (0.00 sec)
+----------+
| count(1) |
+----------+
| 3 |
+----------+
1 row in set (0.00 sec)
结论:1.count(*)等于count(1),而count(col)会忽略null值,而不忽略''值 ;
2.''值不等于null值,''是空字符串。
2.''值不等于null值,''是空字符串。
0 0
- mysql count(*)和count(1)及count(col)的区别测试
- count(*),count(1),count(col)的区别
- count(*)、count(1)和count(col)的区别
- 浅析count(1) count(*) count(col)的区别和性能
- 浅析count(1) count(*) count(col)的区别和性能
- count(1)、count(*)与count(col)的区别
- sql server中count(*),count(col),count(1)的区别
- select count(*) 和select count(1)和select count(col)
- SQL Server中count(*), count(col), count(1)的对比
- SQL Server中count(*), count(col), count(1)的对比
- SQL Server中count(*), count(col), count(1)的对比
- Oracle count(1) count(*) count(col)
- mysql count(*),count(1),count(字段)的区别
- count(*),count(1)和count(field)区别
- count(*),count(1)和count(field)区别
- count(1)和count(*)的区别
- select count(1)和count(*)的区别
- count(*)和count(1)的区别
- hadoop学习序曲之java基础篇--javamap
- 《Linux设备驱动开发详解(第3版)》(即《Linux设备驱动开发详解:基于最新的Linux 4.0内核》)前言
- js操作cookie实现记住密码功能
- java Annotation(注解)(一)
- Spring调度任务cronjob 精确指定任务的运行时间
- mysql count(*)和count(1)及count(col)的区别测试
- FIFO页面置换算法实现(百度笔试题1)
- Android tips
- 理解频率与带宽
- c# sftp 库 Chilkat
- Spark 机器学习 —— KMeans
- return 、 return false、return true区别
- hadoop学习序曲之java基础篇--javaIO流及File类
- hdoj 2111 Saving HDU