select
first_date
,count(distinct case when by_day=0 then yxuserid else null end) as day_0
,count(distinct case when by_day=1 then yxuserid else null end) as day_1
,count(distinct case when by_day=2 then yxuserid else null end) as day_2
,count(distinct case when by_day=3 then yxuserid else null end) as day_3
,count(distinct case when by_day=4 then yxuserid else null end) as day_4
,count(distinct case when by_day=5 then yxuserid else null end) as day_5
,count(distinct case when by_day=6 then yxuserid else null end) as day_6
,count(distinct case when by_day>=7 then yxuserid else null end) as day_7plus
from
(
select
a.yxuserid
,log_date
,first_date
,datediff(log_date,first_date) as by_day
from
(
select
yxuserid
,to_date(from_unixtime(floor(createtime/1000))) as log_date
from
rdb.ods_db_acthd1912shop_tb_yx_common_task_p
where
ds='2019-12-02'
and createtime>=1575043200000
)a
left join
(
select
yxuserid
,min(to_date(from_unixtime(floor(createtime/1000)))) as first_date
from
rdb.ods_db_acthd1912shop_tb_yx_common_task_p
where
ds='2019-12-02'
and createtime>=1575043200000
group by yxuserid
)b
on
a.yxuserid=b.yxuserid
) as t
group by first_date
參考連接:
注意:這樣算出來的是每天新訪uv隨之而來的留存率,並沒有老用戶
老用戶次日留存參考
select
count(distinct a.yxuserid)
,count(distinct b.yxuserid)
,count(distinct b.yxuserid)/count(distinct a.yxuserid)
from
(
select
yxuserid
from
rdb.ods_db_acthd1912shop_tb_yx_common_task_p
where
ds='2019-12-02'
and to_date(from_unixtime(floor(createtime/1000)))='2019-12-02'
)a
left join
(
select
yxuserid
from
rdb.ods_db_acthd1912shop_tb_yx_common_task_p
where
ds='2019-12-02'
and to_date(from_unixtime(floor(createtime/1000)))='2019-12-03'
)b
on
a.yxuserid=b.yxuserid