在MySQL中使用datediff()优化查询 [英] optimizing Query with datediff() in mysql

查看:707
本文介绍了在MySQL中使用datediff()优化查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似下面的查询

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;

我使用了关于它的解释,发现它正在使用基于baseate的索引,我认为date_diff是问题

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

并请告诉我,根据性能,哪种更好的datediff()或to_days()

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

我正在使用mysql 5.5

i am using 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中使用datediff()优化查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆