答案 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;