需要帮助找到9周关键人物的平均运行时间序列数据

问题描述 投票:0回答:2

我有时间序列表中的数据,我需要9周运行运行Demand列的平均值。

[attached is imagee][1].

sql hana
2个回答
0
投票

假设您的RDBMS有avg功能,在这里你去:

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

0
投票

能否请你尝试下面的SQL查询,这算9周平均线(按照行号列实际上现在星期,但下面的9行,包括自己在排序的数据,ID)

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;
© www.soinside.com 2019 - 2024. All rights reserved.