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>
添加回答
舉報