-1
select
    Date, [Close],
    avg([close]) over (order by date asc rows 4 preceding) as MA10
from 
    dbo.APPL

此查询返回股票价格的滚动 4 天平均值。但是,我想显示的值NULL好像前几天小于 4。

如何在 SQL Server 中进行调整?

4

1 回答 1

-1

我认为 JeffUK 的意思是做这样的事情:

select
    Date, [Close],
    case when days >= 4 then MA10 end as MA10
from
(
    select
        Date, [Close],
        avg([close]) over (order by date asc rows 4 preceding) as MA10,
        count([close]) over (order by date asc rows 4 preceding) as days
    from 
        dbo.APPL

) X
于 2018-04-01T07:30:50.590 回答