其他
SQL 语句中你还认为 count(1) 比 count(*) 效率更高吗?
>>号外:关注“Java精选”公众号,回复“面试资料”,免费领取资料!“Java精选面试题”小程序,3000+ 道面试题在线刷,最新、最全 Java 面试题!
1. count(1) and count(*)
mysql> create table counttest(name char(1), age char(2));
Query OK, 0 rows affected (0.03 sec)
mysql> insert into counttest values
-> ('a', '14'),('a', '15'), ('a', '15'),
-> ('b', NULL), ('b', '16'),
-> ('c', '17'),
-> ('d', null),
->('e', '');
Query OK, 8 rows affected (0.01 sec)
Records: 8 Duplicates: 0 Warnings: 0
mysql> select * from counttest;
+------+------+
| name | age |
+------+------+
| a | 14 |
| a | 15 |
| a | 15 |
| b | NULL |
| b | 16 |
| c | 17 |
| d | NULL |
| e | |
+------+------+
8 rows in set (0.00 sec)
mysql> select name, count(name), count(1), count(*), count(age), count(distinct(age))
-> from counttest
-> group by name;
+------+-------------+----------+----------+------------+----------------------+
| name | count(name) | count(1) | count(*) | count(age) | count(distinct(age)) |
+------+-------------+----------+----------+------------+----------------------+
| a | 3 | 3 | 3 | 3 | 2 |
| b | 2 | 2 | 2 | 1 | 1 |
| c | 1 | 1 | 1 | 1 | 1 |
| d | 1 | 1 | 1 | 0 | 0 |
| e | 1 | 1 | 1 | 1 | 1 |
+------+-------------+----------+----------+------------+----------------------+
5 rows in set (0.00 sec)
作者:BigoSprite
blog.csdn.net/iFuMI/article/details/77920767
一张 900w 的数据表,16s 执行的 SQL 优化到 300ms?
一个依赖组件搞定 Spring Boot 反爬虫、接口防盗刷!
都 2021 年了,你还在用 Jenkins ?赶快尝试这 13 种替代方案吧!
Spring Framework 使用时常犯的十大错误,切记不要犯!
Spring Boot 框架中如何使用 AOP 防止重复提交?(附源码)
Google 出品 Java 编码风格规范,强烈推荐,权威又科学!
Spring Cloud 项目中实现推送消息到 RabbitMQ 消息中间件