下面是原始数据,
u01 2017/1/21 5
u02 2017/1/23 6
u03 2017/1/22 8
u04 2017/1/20 3
u01 2017/1/23 6
u01 2017/2/21 8
u02 2017/1/23 6
u01 2017/2/22 4
通过sql统计出每个用户的累计访问次数,如下
u01 2017-01 11 11
u01 2017-02 12 23
u02 2017-01 12 12
u03 2017-01 8 8
u04 2017-01 3 3
语句
select
userId,
mn,
sum_visitCount,
sum(sum_visitCount) over(partition by userId order by mn)
from
(select userId,mn,sum(visitCount) sum_visitCount
from (select userId,
date_format(regexp_replace(visitDate,'/','-'),'yyyy-MM') mn,
visitCount
from action)t1
group by userId,mn)t2;