微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何计算Clickhouse从开始到当天的所有点的每一天的点数

如何解决如何计算Clickhouse从开始到当天的所有点的每一天的点数

我在Clickhouse中有以下数据:

enter image description here

每个用户在一天中的

最终点是从开始到当天的总和(点)。 例如,用户1在2020-07-02中的点是800,而在2020-07-03中的点是200。

我需要这个结果:每个用户每天的积分:

enter image description here

解决方法

select uid,d,t from (
select uid,groupArray(date) dg,arrayCumSum(groupArray(spt)) gt from
(select uid,date,sum(pt) spt from
(select 1 tid,'2020-07-01' date,1 uid,500 pt
union all 
select 1 tid,'2020-07-02' date,300 pt
union all 
select 1 tid,'2020-07-03' date,-600 pt)
group by uid,date
order by uid,date)
group by uid) array join dg as d,gt as t

┌─uid─┬─d──────────┬───t─┐
│   1 │ 2020-07-01 │ 500 │
│   1 │ 2020-07-02 │ 800 │
│   1 │ 2020-07-03 │ 200 │
└─────┴────────────┴─────┘

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。