select q.*,
(select top (1) q2.close
from quotes as q2
where q2.ticker = q.ticker and q2.quotedate < q.quotedate
order by q2.quotedate desc
) as prev_close
from quotes as q;
我不确定您是如何计算更改的,但您可以使用子查询:
select q.*,
(close - prev_close) / prev_close as change_ratio
from (select q.*,
(select top (1) q2.close
from quotes as q2
where q2.ticker = q.ticker and q2.quotedate < q.quotedate
order by q2.quotedate desc
) as prev_close
from quotes as q
) as q;
sel ticker,quotedate,open,high,low,close,
100.00*(abs(close-lag(close) over(order by quotedate)))/lag(close) over(order by quotedate) as change
from table
2条答案
按热度按时间vh0rcniy1#
在任何合理的数据库中
lag()
. 哦,好吧,那就排除了ms的访问权限。您可以使用相关的子查询来实现这一点。以下是上一个收盘价:我不确定您是如何计算更改的,但您可以使用子查询:
g52tjvyc2#
这将是使用lag的典型sql方法