mysql – Sum values ​​by time

id_ | date_ | hora_ | in_ | out_ |
| ... | ... | ... | ... | ...
| 19 | 2018-12-12 | 18: 15: 00 | 1 | 3 |
| 19 | 2018-12-12 | 18: 30: 00 | 1 | 0 |
| 19 | 2018-12-12 | 18: 45: 00 | 2 | 4 |
| 19 | 2018-12-12 | 19: 00: 00 | 2 | 3 |
| 19 | 2018-12-12 | 19: 15: 00 | 2 | 0 |
| 19 | 2018-12-12 | 19: 30: 00 | 2 | 4 |
| 19 | 2018-12-12 | 19: 45: 00 | 1 | 1 |
| 19 | 2018-12-12 | 20: 00: 00 | 1 | 1 |
| 19 | 2018-12-12 | 20: 15: 00 | 0 | 0 |
| 19 | 2018-12-12 | 20: 30: 00 | 1 | 0 |
| 19 | 2018-12-12 | 20: 45: 00 | 0 | 2 |
| 19 | 2018-12-12 | 21: 00: 00 | 1 | 4 |
| 19 | 2018-12-12 | 21: 15: 00 | 3 | 0 |
| 19 | 2018-12-12 | 21: 30: 00 | 3 | 2 |
| 19 | 2018-12-12 | 21: 45: 00 | 0 | 1 |
| 19 | 2018-12-12 | 22: 00: 00 | 0 | 0 |
| 19 | 2018-12-12 | 22: 15: 00 | 1 | 3 |
| 19 | 2018-12-12 | 22: 30: 00 | 1 | 0 |
| 19 | 2018-12-12 | 22: 45: 00 | 2 | 4 |
| 19 | 2018-12-12 | 23: 00: 00 | 2 | 3 |
| 19 | 2018-12-12 | 23: 15: 00 | 0 | 0 |
| 19 | 2018-12-12 | 23: 30: 00 | 0 | 0 |
| 19 | 2018-12-12 | 23: 45: 00 | 0 | 0 |
| 19 | 2018-12-13 | 00: 00: 00 | 1 | 2 |

http://sqlfiddle.com/#!9/9d8554/3

My query

SELECT id_, hora_,
SUM (in_), SUM (out_) FROM Table_ WHERE LIKE_ID & # 39; 19 & # 39; AND date_ LIKE & # 39; 2018-12-07 & # 39;
GROUP BY id_, TIME (hora_)
ORDER PER hour_;

Hello db gurus,
Although I am a frequent visitor to stactoverflow, this is my first question as a newbie.
I came to the conclusion that my query produces erroneous results because, in reality, the real time period starts at x: 00: 15 and ends at x + 1: 00: 00.

I have two "problems". I need to add 4 periods of 1/4 hour from x: 15: 00 to x + 1: 00: 00 and at the end of the day I should include 00:00:00, which is marked with the date of the next day. date. All the help is appreciated.

Example: The results that are written in db at 9:00 am, in fact the values ​​belong to the previous period (08:45:00 to 09:00:00), so I can not use the SUM (in_) for hour.