I have this table:
id | price | sold_at |
---|---|---|
4 | 30 | 2022-01-04 |
3 | 15 | 2022-01-03 |
2 | 30 | 2022-01-02 |
1 | 30 | 2022-01-01 |
And I want to aggregate the price column, but only the consecutive values in the solt_at
timeline. I want to select the latest one.
id | price | sold_at |
---|---|---|
4 | 30 | 2022-01-04 |
3 | 15 | 2022-01-03 |
2 | 30 | 2022-01-02 |
Please note that the two rows with 30
price stay since they have another price in between. I tried GROUP BY
and PARTITION BY
but couldn't find the exact way to do that. Any comment will be appreciated. Thanks.