【发布时间】:2020-08-11 18:29:24
【问题描述】:
我想统计所有在 2019 年 1 月 1 日活跃的唯一身份客户,条件是他们在接下来的 3 天内也活跃。
主表
date customer_id time_spent_online_min
2019-01-01 1 5
2019-01-01 2 6
2019-01-01 3 4
2019-01-02 1 7
2019-01-02 2 5
2019-01-03 3 3
2019-01-04 1 4
2019-01-04 2 6
输出表
date total_active_customers
2019-01-01 2
这是我迄今为止尝试过的:
with cte as(
select customer_id
,date
,time_spent_online_min
from main_table
where date between date '2019-01-01' and date '2019-01-04'
and customer_id is not null)
select date
,count(distinct(customer_id)) as total_active_customers
from cte
where date = date '2019-01-01'
group by 1
【问题讨论】: