2 回答
TA贡献1797条经验 获得超4个赞
如果 TRANS_DATE
为 varchar/char
类型,且该字段有索引,那么大部分情况下第一句比第二句更快
如果 TRANS_DATE
为 timestamp/datetime
类型,两句都用不到索引,全表扫描,所以效率差不多
TA贡献1826条经验 获得超6个赞
mysql> select count(*) from table where date like '2018-08-18%';
+----------+
| count(*) |
+----------+
| 2128 |
+----------+
1 row in set (0.98 sec)
mysql> select count(*) from table where date(date) = '2018-08-18';
+----------+
| count(*) |
+----------+
| 2128 |
+----------+
1 row in set (1.21 sec)
mysql> select count(*) from table where date(date) = '2018-08-18';
+----------+
| count(*) |
+----------+
| 2128 |
+----------+
1 row in set (1.21 sec)
mysql> select count(*) from table where date like '2018-08-18%';
+----------+
| count(*) |
+----------+
| 2128 |
+----------+
1 row in set (0.98 sec)
mysql> select count(*) from table;
+----------+
| count(*) |
+----------+
| 2066946 |
+----------+
1 row in set (0.66 sec)
mysql>
添加回答
举报