SelectDB Cloud
SQL 手册
函数
window-functions
WINDOW-FUNCTION-AVG

WINDOW FUNCTION AVG

description

计算窗口内数据的平均值

AVG([DISTINCT | ALL] *expression*) [OVER (*analytic_clause*)]

example

计算当前行和它前后各一行数据的x平均值

select x, property,    
avg(x) over    
(   
partition by property    
order by x    
rows between 1 preceding and 1 following    
) as 'moving average'    
from int_t where property in ('odd','even');
 
 | x  | property | moving average |
 |----|----------|----------------|
 | 2  | even     | 3              |
 | 4  | even     | 4              |
 | 6  | even     | 6              |
 | 8  | even     | 8              |
 | 10 | even     | 9              |
 | 1  | odd      | 2              |
 | 3  | odd      | 3              |
 | 5  | odd      | 5              |
 | 7  | odd      | 7              |
 | 9  | odd      | 8              |

keywords

WINDOW,FUNCTION,AVG
© 2023 北京飞轮数据科技有限公司 京ICP备2022004029号 | Apache、Apache Doris 以及相关开源项目名称均为 Apache 基金会商标