I'm trying to figure out how i can improve the performance of this query and i believe it may be my indexes; some of my thoughts are that date may be causing the poor performance or that i have the indexs in the order wrong. Also are there any other suggestions anyone has on how to improve the speed that are not index related? Thanks, i look forward to any input!
Here's what I've tried so far
ALTER TABLE data ADD INDEX(data_timestamp, first,last);
ALTER table data add index(first);
ALTER table data add index(first);
ALTER TABLE data add index (data_timestamp);
The following query(the second one) below runs a subquery for each row of a database in order to get the previous average at the instant of each point
select count(*) from data where data_timestamp like '2015-01-01%'; -> 362855
select (select sum(first*last) / sum(last)
FROM data t2
WHERE data_timestamp like '2015-12-18%'
AND t2.data_timestamp <= t1.data_timestamp
), t1.*
FROM data t1
WHERE data_timestamp like '2015-12-18%';