I have two tables with weather data that are frequently updated. Table A has data with 10 min interval and table B with 1 hour interval.
Table A (realized weather)
| observationtime | temperature |
|---|---|
| 17/02/21 00:00 | 9 |
| 17/02/21 00:10 | 9 |
| 17/02/21 00:20 | 9 |
| 17/02/21 00:30 | 9 |
| ... | ... |
| 17/02/21 03:00 | 9 |
Table B (weather forecast)
| observationtime | temperature |
|---|---|
| 17/02/21 04:00 | 9 |
| 17/02/21 05:00 | 9 |
| 17/02/21 06:00 | 9 |
| 17/02/21 07:00 | 9 |
What I want
| observationtime | realized_temperature | forecasted_temperature |
|---|---|---|
| 17/02/21 00:00 | 9 | |
| 17/02/21 01:00 | 9 | |
| 17/02/21 02:00 | 9 | |
| 17/02/21 03:00 | 9 | |
| 17/02/21 04:00 | 9 | |
| 17/02/21 05:00 | 9 | |
| 17/02/21 06:00 | 9 | |
| 17/02/21 07:00 | 9 |
So as far as I can gather three things need to happen:
- First I need to get the smallest timestamp from table A and round it down the smallest whole hour
- Get the max timestamp from the forecast table
- Generate a series between these two timestamps with 1 hour intervals
- Join Table A and B on the generated series
Can't quite figure out how to do this. Anyone have the solution?