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

 

上一篇:PTA 翁恺 7-42 整除光棍


下一篇:42. 接雨水