需要帮助找到9周的关键指标的运行平均值以获得时间序列数据

时间:2019-02-06 12:17:31

标签: sql hana

我有时间序列表数据,我需要连续9周连续运行Demand列。

[attached is imagee][1].

2 个答案:

答案 0 :(得分:0)

假设您的RDBMS在此处具有avg功能,您可以进行以下操作:

select avg(demand)
from yourtable
where week_series >= 1 and week_series <= 9;

答案 1 :(得分:0)

请问您可以尝试执行以下SQL查询,这将计算出9周的平均值(实际上现在是周数,但会根据ROW number列ID在以下9行中包括自身)

with cte as (
    select
        cast(substring(id,4,length(id)) as integer) as rid,
        id,week1,demand
    from demands
)
select
c.*,
(select sum(t.demand) from cte t where t.rid between c.rid and (8 + c.rid)) as smm
from cte c;