没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
MySQL中中count(*)、、count(1)和和count(col)的区别汇总的区别汇总
count()函数是用来统计表中记录的一个函数,返回匹配条件的行数,下面这篇文章主要给大家总结介绍了关于
MySQL中count(*)、count(1)和count(col)的区别,文中通过示例代码介绍的非常详细,需要的朋友可以参考下。
前言前言
count函数是用来统计表中或数组中记录的一个函数,count(*) 它返回检索行的数目, 不论其是否包含 NULL值。最近感觉大
家都在讨论count的区别,那么我也写下吧:欢迎留言讨论,话不多说了,来一起看看详细的介绍吧。
1、表结构:、表结构:
dba_jingjing@3306>[rds_test]>CREATE TABLE `test_count` (
-> `c1` varchar(10) DEFAULT NULL,
-> `c2` varchar(10) DEFAULT NULL,
-> KEY `idx_c1` (`c1`)
-> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.11 sec)
2、插入测试数据:、插入测试数据:
dba_jingjing@3306>[rds_test]>insert into test_count values(1,10);
Query OK, 1 row affected (0.03 sec)
dba_jingjing@3306>[rds_test]>insert into test_count values(abc,null);
ERROR 1054 (42S22): Unknown column 'abc' in 'field list'
dba_jingjing@3306>[rds_test]>insert into test_count values('abc',null);
Query OK, 1 row affected (0.04 sec)
dba_jingjing@3306>[rds_test]>insert into test_count values(null,null);
Query OK, 1 row affected (0.04 sec)
dba_jingjing@3306>[rds_test]>insert into test_count values('368rhf8fj',null);
Query OK, 1 row affected (0.03 sec)
dba_jingjing@3306>[rds_test]>select * from test_count;
+-----------+------+
| c1 | c2 |
+-----------+------+
| 1 | 10 |
| abc | NULL |
| NULL | NULL |
| 368rhf8fj | NULL |
+-----------+------+
4 rows in set (0.00 sec)
测试:测试:
dba_jingjing@3306>[rds_test]>select count(*) from test_count;
+----------+
| count(*) |
+----------+
| 4 |
+----------+
1 row in set (0.00 sec)
EXPLAIN: {
"query_block": {
"select_id": 1,
"message": "Select tables optimized away"
1 row in set, 1 warning (0.00 sec)
dba_jingjing@3306>[rds_test]>select count(1) from test_count;
+----------+
| count(1) |
+----------+
| 4 |
+----------+
1 row in set (0.00 sec)
EXPLAIN: {
"query_block": {
"select_id": 1,
"message": "Select tables optimized away"
1 row in set, 1 warning (0.00 sec)
dba_jingjing@3306>[rds_test]>select count(c1) from test_count;
+-----------+
| count(c1) |
+-----------+
资源评论
weixin_38720762
- 粉丝: 4
- 资源: 943
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功