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

2020-01-05 15:39:46 浏览数 (3)

1.传统的方法

代码语言:javascript复制
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,能有效的提高效率。

代码语言:javascript复制
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

0 人点赞