optimizing Query with datediff() in mysql

2019-06-14 12:09发布

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条回答
爷、活的狠高调
2楼-- · 2019-06-14 12:11

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);
查看更多
登录 后发表回答