各位帮忙看下,下面的sql能不能优化一下,现在运行这个sql很慢select t.datrpt as 日期,sum(t.intimei) as 累计用户量,sum(i.intimei) as 新增用户量,sum(a.intactive) as 活跃用户量
from tb_rpt_hudee_appid_imei_total_day t,tb_base_hudee_app_distribution d,tb_rpt_hudee_appid_imei_day i,tb_rpt_hudee_appid_imei_active_day a
where t.varappid=d.varappid
and i.varappid=d.varappid
and a.varappid=d.varappid
and d.flag='1'
and t.datrpt>=DATE_SUB(CURDATE(),INTERVAL 7 day)
and t.datrpt=i.datrpt
and t.datrpt=a.datrpt
GROUP BY 日期
ORDER BY 日期 desc
from tb_rpt_hudee_appid_imei_total_day t,tb_base_hudee_app_distribution d,tb_rpt_hudee_appid_imei_day i,tb_rpt_hudee_appid_imei_active_day a
where t.varappid=d.varappid
and i.varappid=d.varappid
and a.varappid=d.varappid
and d.flag='1'
and t.datrpt>=DATE_SUB(CURDATE(),INTERVAL 7 day)
and t.datrpt=i.datrpt
and t.datrpt=a.datrpt
GROUP BY 日期
ORDER BY 日期 desc
2、如果连接没问题的话,那么就是在连接条件和group by条件上建索引了,其他没什么好优化的
3、你这date_sub看起来貌似是mysql的,这里是mssql,你走错地方了
and i.varappid=d.varappid
and a.varappid=d.varappid
and d.flag='1'
and t.datrpt>=DATE_SUB(CURDATE(),INTERVAL 7 day)
and t.datrpt=i.datrpt
and t.datrpt=a.datrpt