I'm working on candlestick chart data. I have a database table (MySql) with
created value
2017-09-25 17:55:04 3322.09
2017-09-25 18:00:03 3317.49
2017-09-25 18:05:02 3316.12
2017-09-25 18:10:03 3325.16
2017-09-25 18:15:04 3326.01
2017-09-25 18:20:03 3330.49
2017-09-25 18:25:04 3331.49
2017-09-25 18:30:04 3335.24
2017-09-25 18:35:03 3347.13
2017-09-25 18:40:03 3343.21
2017-09-25 18:45:05 3341.78
2017-09-25 18:50:03 3339.64
2017-09-25 18:55:04 3336.12
2017-09-25 19:00:04 3327.73
2017-09-25 19:05:03 3327.96
2017-09-25 19:10:04 3325.93
And I'm trying to select a maximum, minimum, open value, close value for any period of time (e.g. 15 minutes or every 4 hours, every 6 days etc.)
So far I have
SELECT p.created, HOUR(`DATE`), MAX(p.value), MIN(p.value)
FROM price
GROUP BY DATE(`DATE`),HOUR(`DATE`)
Not so complicated. It gives me maximum and minimum from every hour, so for minutes and "full" periods like days, weeks, month I can use MONTH, DAY etc. functions.
Any idea how to build a query for any period of time, let's say 28 minutes or 31 hours etc? Also, this works for maximum and minimum, but I also need a opening value (first) for time period and close value (last).