使用SQL,我如何在给定的天数内对每个天数内未指定数量的记录进行滚动平均?
我有以下字段。下面的每条记录都是唯一的 我想得到前几天每个不同的“记录类型”和“某种类型”的字段“得分”的滚动平均值 数据: 期望输出: SQL查询:使用SQL,我如何在给定的天数内对每个天数内未指定数量的记录进行滚动平均?,sql,postgresql,select,average,window-functions,Sql,Postgresql,Select,Average,Window Functions,我有以下字段。下面的每条记录都是唯一的 我想得到前几天每个不同的“记录类型”和“某种类型”的字段“得分”的滚动平均值 数据: 期望输出: SQL查询: select date ,record_type ,something_ind ,avg(score) over(partition by date, record_type, something_ind order by date, record_type, something_ind rows betwe
select
date
,record_type
,something_ind
,avg(score) over(partition by date, record_type, something_ind order by date, record_type, something_ind rows between 6 preceding and current row as rolling_average_score
from table
group by 1,2,3
我想得到每个不同的记录类型
和某个类型
在所有前几天的得分的滚动平均值
使用窗口功能。我理解你的问题,你想要:
select
t.*,
avg(score) over(
partition by record_type, something_ind
order by date
) avg_score
from mytable t
“滚动平均”是指“累计平均”吗?