I am new to SQL, where I am trying to split time intervals into multiple rows of one hour, together with an indicator of how many minutes the interval overlaps each hour.
My data:
validitybegin | validityend | ticketid |
---------------------+---------------------+------------------+
2017-08-31 12:22:04 | 2017-08-31 13:08:56 | ID1 |
2017-08-31 13:09:02 | 2017-08-31 16:46:51 | ID2 |
2017-08-31 13:09:10 | 2017-08-31 14:09:10 | ID3 |
What I would like:
start | end | overlap | ticketid |
---------------------+---------------------+-------------+------------------+
2017-08-31 12:00:00 | 2017-08-31 13:00:00 | 38 | ID1 |
2017-08-31 13:00:00 | 2017-08-31 14:00:00 | 9 | ID1 |
2017-08-31 13:00:00 | 2017-08-31 14:00:00 | 51 | ID2 |
2017-08-31 14:00:00 | 2017-08-31 15:00:00 | 60 | ID2 |
2017-08-31 15:00:00 | 2017-08-31 16:00:00 | 60 | ID2 |
2017-08-31 16:00:00 | 2017-08-31 17:00:00 | 47 | ID2 |
2017-08-31 13:00:00 | 2017-08-31 14:00:00 | 51 | ID3 |
2017-08-31 14:00:00 | 2017-08-31 15:00:00 | 9 | ID3 |
What would be the easiest/fastest way to do this?