CDA持证人阿涛哥

2021-11-01   阅读量: 4064

Mysql

计算任意连续7天的累计客户数

扫码加入数据分析学习群
#### 计算任意连续7天的累计客户数,假设表里有3个字段, c_id 客户ID,order_id,order_date
示例日期为17年7月1日到17年7月30日

#答案如下
select order_date 开始日期,date(order_date+ 6 ) 截止日期,concat(order_date,'~',date(order_date+6)) 时间段,
sum(count(distinct c_id)) over( order by order_date rows between current row and 6 following) as 7天人数
from order_info
where order_date between '2017-07-01' and '2017-07-30'
and date(order_date+6 ) is not null  # 出现类似'2017-7-32'就是 null。
group by order_date ;

image.png

5.5560 2 3 关注作者 收藏

评论(3)

学无止境
2021-12-02

谢谢

0.0000 0 0 回复
CDA持证人阿涛哥
2021-11-11

谢谢夸赞

0.0000 0 0 回复
学无止境
2021-11-08

真不错

0.0000 0 0 回复
CDA持证人阿涛哥
2021-11-11

谢谢夸赞

0.0000 0 0 回复
CDA持证人阿涛哥
2021-11-11

谢谢夸赞

0.0000 0 0 回复
CDA持证人阿涛哥
2021-11-11

谢谢夸赞

0.0000 0 0 回复
CDA持证人阿涛哥
2021-11-11

谢谢夸赞

0.0000 0 0 回复
CDA持证人阿涛哥
2021-11-11

谢谢夸赞

0.0000 0 0 回复
CDA持证人阿涛哥
2021-11-11

谢谢夸赞

0.0000 0 0 回复
CDA持证人阿涛哥
2021-11-11

谢谢夸赞

0.0000 0 0 回复

推荐课程