BETWEEN

回覆文章
yehlu
Site Admin
文章: 3245
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

BETWEEN

文章 yehlu »

代碼: 選擇全部

MariaDB [test1]> EXPLAIN SELECT * FROM  `sell_pp` WHERE  date like '2008-10-10%';
+------+-------------+---------+------+---------------+------+---------+------+---------+-------------+
| id   | select_type | table   | type | possible_keys | key  | key_len | ref  | rows    | Extra       |
+------+-------------+---------+------+---------------+------+---------+------+---------+-------------+
|    1 | SIMPLE      | sell_pp | ALL  | date          | NULL | NULL    | NULL | 2615279 | Using where |
+------+-------------+---------+------+---------------+------+---------+------+---------+-------------+
1 row in set (0.00 sec)

MariaDB [test1]> EXPLAIN SELECT * FROM  `sell_pp` WHERE  date >= '2008-10-10 00:00:00' and date <= '2008-10-10 23:59:59';
+------+-------------+---------+-------+---------------+------+---------+------+------+-------------+
| id   | select_type | table   | type  | possible_keys | key  | key_len | ref  | rows | Extra       |
+------+-------------+---------+-------+---------------+------+---------+------+------+-------------+
|    1 | SIMPLE      | sell_pp | range | date          | date | 8       | NULL |  669 | Using where |
+------+-------------+---------+-------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)

MariaDB [test1]> EXPLAIN SELECT * FROM  `sell_pp` WHERE  date  BETWEEN '2008-10-10 00:00:00' and  '2008-10-10 23:59:59';
+------+-------------+---------+-------+---------------+------+---------+------+------+-------------+
| id   | select_type | table   | type  | possible_keys | key  | key_len | ref  | rows | Extra       |
+------+-------------+---------+-------+---------------+------+---------+------+------+-------------+
|    1 | SIMPLE      | sell_pp | range | date          | date | 8       | NULL |  669 | Using where |
+------+-------------+---------+-------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)
回覆文章

回到「MySQL」