I am trying to prepare data for a candle stick chart. I have some records on MySQL database as shown below:
| Rate | Date |
|----------|---------------------|
| 0.001111 | 2017-11-12 19:13:05 |
| 0.001214 | 2017-11-12 19:14:11 |
| 0.001612 | 2017-11-12 19:15:42 |
| 0.001231 | 2017-11-12 19:16:23 |
| 0.001514 | 2017-11-12 19:17:23 |
| 0.001611 | 2017-11-12 19:26:33 |
| 0.001421 | 2017-11-12 19:27:25 |
| 0.001214 | 2017-11-12 19:28:27 |
| 0.001611 | 2017-11-12 19:29:55 |
|----------|---------------------|
I want to group below data as shown below:
| Rate | Date |
|----------|---------------------|
| 0.002325 | 2017-11-12 19:10:00 |
| 0.004357 | 2017-11-12 19:15:00 |
| 0.004357 | 2017-11-12 19:20:00 | # Auto generated record of missing record.
| 0.005857 | 2017-11-12 19:25:00 |
|----------|---------------------|
I was trying to understand calendar table, but I wasn't able to do with that.
I also followed this link https://stackoverflow.com/questions/4342370/grouping-into-interval-of-5-minutes-within-a-time-range but still failed.
UPDATE:
This is my sample query that I am using currently to get data with date sorting and grouping.
SELECT
SUM(exchange_rat) AS totalAmount,
DATE_FORMAT(from_unixtime(unix_timestamp(created_at) - unix_timestamp(created_at) mod 300), '%Y-%m-%d %H:%i:00') as createdAt
from payments group by createdAt
Best Answer
This is a very basic implementation of a calendar table. As you cans see, it simply group dates using intervals.
rextester here
For the second part of the question, you should explain how to auto-generate the desired values.