2025-04-30 17:17:09 +08:00
|
|
|
CREATE TABLE datasci.ads_996eco_index_box_m (
|
|
|
|
index_type text,
|
2025-05-07 20:41:31 +08:00
|
|
|
data_day text,
|
2025-04-30 17:17:09 +08:00
|
|
|
is_box text,
|
2025-05-07 20:41:31 +08:00
|
|
|
new_user_num bigint,
|
|
|
|
ret_1 bigint,
|
|
|
|
ret_7 bigint,
|
|
|
|
ret_14 bigint,
|
|
|
|
ret_30 bigint,
|
|
|
|
ret_60 bigint,
|
|
|
|
ret_90 bigint,
|
|
|
|
ret_180 bigint,
|
2025-04-30 17:17:09 +08:00
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
INSERT INTO
|
2025-05-07 20:41:31 +08:00
|
|
|
datasci.ads_996eco_index_box_m (index_type,data_day,is_box,new_user_num,ret_1,ret_7,ret_14,ret_30,ret_60,ret_90,ret_180)
|
|
|
|
DELETE FROM datasci.ads_996eco_index_box_m WHERE ds = '${month}';
|
2025-04-30 17:17:09 +08:00
|
|
|
|
2025-05-07 20:41:31 +08:00
|
|
|
with retention_new_acc as
|
2025-04-30 17:17:09 +08:00
|
|
|
(
|
2025-05-07 20:41:31 +08:00
|
|
|
select
|
|
|
|
t1.appid,t1.app_name,t1.channel,t1.event_time,t1.user_id,t1.ds::date as new_acc_dt,coalesce(t2.user_flag,'非盒子用户') as user_flag
|
|
|
|
from
|
|
|
|
(
|
|
|
|
select
|
|
|
|
account,appid,app_name,channel,event_time,user_id,ds,row_number() over(partition by user_id order by event_time asc) as rn
|
|
|
|
from
|
|
|
|
(
|
|
|
|
select
|
|
|
|
appid,gm.name as app_name,account,name_abbr,channel,event_time,user_id,ds
|
|
|
|
from public.ods_newly_account acc
|
|
|
|
inner join
|
|
|
|
(
|
|
|
|
select id,name,bind_game_id,a.account,b.name_abbr
|
|
|
|
from public.gm_apply a
|
|
|
|
left join public.dim_gm_info b on a.account=b.account
|
|
|
|
where bind_game_type=1
|
|
|
|
) gm on acc.appid=gm.id
|
2025-04-30 17:17:09 +08:00
|
|
|
) t
|
2025-05-07 20:41:31 +08:00
|
|
|
) t1
|
|
|
|
left join datasci.dws_plt_newly_account_d t2 on t1.user_id=t2.user_id
|
|
|
|
where rn=1
|
|
|
|
and t1.ds between '${hisdate}' and '${bizdate}'
|
|
|
|
--and user_id='1419067566'
|
|
|
|
),
|
|
|
|
retention_active_detail as
|
2025-04-30 17:17:09 +08:00
|
|
|
(
|
2025-05-07 20:41:31 +08:00
|
|
|
select
|
|
|
|
ds::date as dt,user_id
|
|
|
|
from public.ods_active_account t1
|
|
|
|
inner join
|
|
|
|
(
|
|
|
|
select id,name,bind_game_id
|
|
|
|
from public.gm_apply
|
|
|
|
where bind_game_type=1
|
|
|
|
) t2 on t1.appid=t2.id
|
|
|
|
where t1.ds>='${hisdate}' and t1.ds<=to_char(dateadd('${bizdate}'::date,31,'dd'),'yyyymmdd')
|
|
|
|
group by
|
|
|
|
ds::date,user_id
|
|
|
|
),
|
|
|
|
retention_rd as
|
2025-04-30 17:17:09 +08:00
|
|
|
(
|
2025-05-07 20:41:31 +08:00
|
|
|
select
|
|
|
|
user_flag,appid,app_name,channel,event_time,t1.user_id,new_acc_dt,t2.dt as act_dt,t2.dt-t1.new_acc_dt as rd
|
|
|
|
from retention_new_acc t1
|
|
|
|
left join retention_active_detail t2 on t1.user_id=t2.user_id
|
|
|
|
--left join 加玩法版本啥的
|
|
|
|
where t2.dt-t1.new_acc_dt in (0,1,7,14,30,60,90,180)
|
|
|
|
--t1.user_id='1419067566'
|
2025-04-30 17:17:09 +08:00
|
|
|
)
|
2025-05-07 20:41:31 +08:00
|
|
|
--渠道留存
|
|
|
|
select
|
|
|
|
t1.user_flag,t1.new_acc_dt,t1.new_user_num,t2.ret_1,ret_7,ret_14,ret_30,ret_60,ret_90,ret_180
|
|
|
|
from
|
2025-04-30 17:17:09 +08:00
|
|
|
(
|
2025-05-07 20:41:31 +08:00
|
|
|
select
|
|
|
|
user_flag,new_acc_dt,uniq(user_id) as new_user_num
|
|
|
|
from retention_rd
|
|
|
|
where rd=0
|
|
|
|
group by
|
|
|
|
user_flag,new_acc_dt
|
|
|
|
) t1
|
|
|
|
left join
|
2025-04-30 17:17:09 +08:00
|
|
|
(
|
2025-05-07 20:41:31 +08:00
|
|
|
select
|
|
|
|
user_flag,new_acc_dt,
|
|
|
|
uniq(case when rd=1 then user_id else null end) as ret_1,
|
|
|
|
uniq(case when rd=7 then user_id else null end) as ret_7,
|
|
|
|
uniq(case when rd=14 then user_id else null end) as ret_14,
|
|
|
|
uniq(case when rd=30 then user_id else null end) as ret_30,
|
|
|
|
uniq(case when rd=60 then user_id else null end) as ret_60,
|
|
|
|
uniq(case when rd=90 then user_id else null end) as ret_90,
|
|
|
|
uniq(case when rd=180 then user_id else null end) as ret_180
|
|
|
|
from retention_rd
|
|
|
|
where rd>0
|
|
|
|
group by
|
|
|
|
user_flag,new_acc_dt
|
|
|
|
) t2 on t1.new_acc_dt=t2.new_acc_dt and t1.user_flag=t2.user_flag
|
2025-04-30 17:17:09 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
|