[英]Sql = how to calculate the return vector with a time series of prices?
我有一个表,其中包含price
和date
列,按升序排列。 我需要据此计算返回向量,其中return = price ( i) / price ( i- 1)
。 时间不是基于时间的,这意味着一条记录可以在9h34,下一条在9h35,然后在9h40等。
我发现了以下主题:用于计算返回数据结果的SQL语法,但是在Oracle中我无法在子查询中使用order by,请您能帮我吗?
在Oracle中,您可以使用lag
分析功能:
select
price / (lag(price) over (order by i))
, ...
from PriceHistory
在此, lag(price) over (order by i)
返回由i
列排序的集合中前一行的价格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.