Select date, symbol, open, high, low, cts.close, volume, lag(cts.close) over (PARTITION by date, symbol) as prevclose,
((cts.close - cts.open) / cts.close) * 100 as prcnt
from cts
where cts.close <> 0;
保持整列prevclose为null。
这很可能是因为您正在按作为时间组件的date
列进行分区。每个分区都是唯一的,因此没有"prev"值。
没有CCD_ 3的CCD_ 2也是没有意义的。订单没有保证。
SELECT ..., lag(cts.close) over (PARTITION by date, symbol) as prevclose
FROM cts;
在我看来应该是
SELECT ..., lag(cts.close) over (PARTITION BY symbol ORDER BY date) as prevclose
FROM cts;