SelectDB Cloud
SQL 手册
SQL 函数
分析(窗口)函数
WINDOW_FUNCTION_COUNT

WINDOW FUNCTION COUNT

description

计算窗口内数据出现次数

COUNT(expression) [OVER (analytic_clause)]

example

计算从当前行到第一行x出现的次数。

select x, property,   
count(x) over   
(   
partition by property    
order by x    
rows between unbounded preceding and current row    
) as 'cumulative total'    
from int_t where property in ('odd','even');
 
 | x  | property | cumulative count |
 |----|----------|------------------|
 | 2  | even     | 1                |
 | 4  | even     | 2                |
 | 6  | even     | 3                |
 | 8  | even     | 4                |
 | 10 | even     | 5                |
 | 1  | odd      | 1                |
 | 3  | odd      | 2                |
 | 5  | odd      | 3                |
 | 7  | odd      | 4                |
 | 9  | odd      | 5                |

keywords

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