I need to transform rows on a monthly basis to rows with a time window based on alternating values. I have already tried various versions of partition, dense_rank and joins with row_number on row_number-1 but I somehow cannot get to the right result.
Here's my data:
month_ID | Value |
---|---|
202211 | 10 |
202212 | 10 |
202301 | 10 |
202302 | 12 |
202303 | 12 |
202304 | 10 |
202305 | 10 |
202306 | 12 |
202307 | 12 |
Here's what I want my output to be:
From | To | Value |
---|---|---|
202211 | 202301 | 10 |
202302 | 202303 | 12 |
202304 | 202305 | 10 |
202306 | 202307 | 12 |
The time frames can differ.