mysql 日期与索引问题

日期类型可以直接和string格式的字符串比较

select * from xxx where event_time>'2018-06-02' 可以使用索引

select * from xxx where date(event_time)>'2018-06-02'   不能使用索引

如果时间戳日期和时间都要比较, 最好使用两个字段保存这个时间戳, 这样可以利用索引

https://stackoverflow.com/questions/2758486/mysql-compare-date-string-with-string-from-datetime-field

猜你喜欢

转载自www.cnblogs.com/yszzu/p/9255769.html