我有一个如下的查询
select
id,name,baseid,member_card_type,membercard_num,last_draw,counter
from details_dest
where datediff(curdate(),basedate)<100;
我已经使用了解释,发现它使用的是基于 basedate 的索引,我认为 date_diff 是问题所在
所以请建议我有没有其他方法可以在没有任何功能的情况下执行它
请根据性能告诉我 datediff() 或 to_days() 哪个更好
我正在使用 mysql 5.5
最佳答案
我会建议以下查询:
select
id,name,baseid,member_card_type,membercard_num,last_draw,counter
from details_dest
where basedate > (curdate() - INTERVAL 100 DAY);
关于mysql - 在 mysql 中使用 datediff() 优化查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15719710/