I have a table A like
LDTS | LENGTH |
---|---|
2022-03-03 15:41:05.685 | 50 |
2022-03-03 15:42:08.203 | NULL |
2022-06-08 21:57:07.909 | 45 |
2022-06-28 21:58:43.558 | 70 |
I want to display the changes in length side by side in two columns, rather than vertical
So for example I would like a result like this
LDTS | FROM_LENGTH | TO_LENGTH |
---|---|---|
2022-03-03 15:42:08.203 | 50 | NULL |
2022-06-08 21:57:07.909 | NULL | 45 |
2022-06-28 21:58:43.558 | 45 | 70 |
where the timestamp (LDTS) would become the timestamp when the value changed (for example the length changed from 50 to null at time 2022-03-03 15:42:08.203). Is there a way I can achieve this?
I was trying something like:
select LDTS, LENGTH AS FROM_LENGTH
lag(LENGTH) over (partition by LDTS order by LDTS) as TO_LENGTH
from TABLE_1;