MySQL Forums
Forum List  »  General

Aggregate intraday data
Posted by: Alberto Pedroni
Date: January 15, 2014 10:16AM

Hi all,

I store stock market data 1 minute per row, I have 511 1 minute rows for every day (from 0900 up to 1730), and I have this query to perform data aggregation from intraday to daily data

SELECT symbol, date, MAX(high) AS high, MIN(low) as low, SUM(volume) as volume,
(select open from F a2 where a1.symbol = a2.symbol and a1.date = a2.date order by time limit 1) as open,
(select close from F a2 where a1.symbol = a2.symbol and a1.date = a2.date order by time desc limit 1) as close
FROM F a1
WHERE date >= date_sub(CURDATE(), interval 100 day)
GROUP BY symbol, date
ORDER BY symbol, date;

but this return less then 100 daily aggregated rows since it use calendar days.

1) How to modify this query to get 100 daily aggregated rows?

2) How to aggregate to 5 minute data instead of daily (i.e., first row aggregates data from 0900 up to 0904, then from 0905 up to 0909, etc.)?

I use mySQL 5.6.11, data stored are as follow

http://s18.postimg.org/4uj8e0mfd/Z514.png

Thanks

Options: ReplyQuote


Subject
Written By
Posted
Aggregate intraday data
January 15, 2014 10:16AM
January 15, 2014 11:33AM
January 16, 2014 03:24AM
January 16, 2014 07:15PM
January 17, 2014 04:56AM
January 17, 2014 02:25PM
January 30, 2014 06:49AM
January 16, 2014 07:10PM
January 17, 2014 04:36AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.