optimizing Query with datediff() in mysql

依然范特西╮ 提交于 2019-12-10 12:08:30

问题


I have a Query like below

select 
id,name,baseid,member_card_type,membercard_num,last_draw,counter 
from details_dest
where datediff(curdate(),basedate)<100;

i have used the explain on that and found it is using index which is on basedate and i think date_diff is the problem

so please suggest me is there any other way to execute it without any functions

and kindly tell me which is better datediff() or to_days() in according to performance

i am using mysql 5.5


回答1:


I would suggest the following query:

select 
id,name,baseid,member_card_type,membercard_num,last_draw,counter 
from details_dest
where basedate > (curdate() - INTERVAL 100 DAY);


来源:https://stackoverflow.com/questions/15719710/optimizing-query-with-datediff-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!