表中列的值为0时,怎么得到它前一行的值

想指教一下,如果我有下图綠色這個表,在 dolphinDb 裏面有冇一個有效方法可以令我找到同一個 symbol 之前的record 而 value 不是0?i.e. i want to have the yellow ones.

attachments-2021-11-IiB13Cu5618b629d6ab62.png

请先 登录 后评论

1 个回答

jinzhi

参考如下实现:

t1 = `T1`T2`T3`T4`T5`T6`T7
s1 = `A`A`A`A`A`A`
b1= 0.35 0.34 0.33 0.28 0.29 0 0.3
a1 =0.34 0.33 0.32 0.3 0 0 0.31
t = table(t1 as timestamp, s1 as symbol, b1 as bid, a1 as ask)
select  *,ffill(iif(prev(bid)==0,NULL,prev(bid))) as last_bid, ffill(iif(prev(bid)==0,NULL,prev(timestamp))) as last_bid_timestamp,  ffill(iif(prev(ask)==0,NULL,prev(ask))) as last_ask,  ffill(iif(prev(ask)==0,NULL,prev(timestamp))) as last_ask_timestamp from t
请先 登录 后评论