mysql datetime、timestamp时间比较 性能提升

1.传统的方法

SELECT * FROM customer lastlogintime   >=  '2015-01-01 13:50:42'   AND   lastlogintime   <=  '2015-02-06 00:00:00'   ORDER BY ID DESC

但是传统的方法效率很低。
2.采用UNIX_TIMESTAMP,能有效的提高效率。

SELECT * FROM customer WHERE UNIX_TIMESTAMP(lastlogintime)  >= UNIX_TIMESTAMP('2015-01-01 13:50:42')  AND  UNIX_TIMESTAMP(lastlogintime)  <= UNIX_TIMESTAMP('2015-02-06 00:00:00')  ORDER BY ID DESC

 

posted @ 2021-10-25 11:51  郭慕荣  阅读(352)  评论(0编辑  收藏  举报