简体   繁体   中英

Sequence data tracking in Redshift table

I have a data like given image.I want to track the all group changes based on reportdate sequence.

Ex: If take 'A' data should balance=1.5 and date='9/30/2015' and 'C' balance=2.05 and date='12/01/2017'.

在此处输入图片说明

I have tried with sql but it tracked all the changes like A to B , A to C and A to D any method to resolve this script?

I think you are describing lead() :

select t.*,
       lead(balance) over (partition by number order by date) as next_balance
from t

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM