提交2
This commit is contained in:
parent
386213caee
commit
2d3d2eb15e
@ -1,281 +1,102 @@
|
|||||||
CREATE TABLE datasci.ads_996eco_index_box_m (
|
CREATE TABLE datasci.ads_996eco_index_box_m (
|
||||||
index_type text,
|
index_type text,
|
||||||
data_month text,
|
data_day text,
|
||||||
is_box text,
|
is_box text,
|
||||||
act_cnt bigint,
|
new_user_num bigint,
|
||||||
pay_cnt bigint,
|
ret_1 bigint,
|
||||||
pay_amount bigint,
|
ret_7 bigint,
|
||||||
mau bigint,
|
ret_14 bigint,
|
||||||
device_type text,
|
ret_30 bigint,
|
||||||
device_type_new text,
|
ret_60 bigint,
|
||||||
act_num bigint,
|
ret_90 bigint,
|
||||||
reg_count bigint,
|
ret_180 bigint,
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
INSERT INTO
|
||||||
|
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}';
|
DELETE FROM datasci.ads_996eco_index_box_m WHERE ds = '${month}';
|
||||||
|
|
||||||
|
with retention_new_acc as
|
||||||
--付费人数和金额
|
|
||||||
WITH ga AS
|
|
||||||
(
|
(
|
||||||
SELECT id
|
select
|
||||||
,name
|
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
|
||||||
,bind_game_id
|
from
|
||||||
FROM public.gm_apply
|
|
||||||
WHERE bind_type = 1
|
|
||||||
AND bind_game_type = 1
|
|
||||||
)
|
|
||||||
,box_users AS
|
|
||||||
(
|
(
|
||||||
SELECT user_id
|
select
|
||||||
FROM public.ods_newly_account
|
account,appid,app_name,channel,event_time,user_id,ds,row_number() over(partition by user_id order by event_time asc) as rn
|
||||||
WHERE appid = 1015
|
from
|
||||||
GROUP BY user_id
|
|
||||||
)
|
|
||||||
,po AS
|
|
||||||
(
|
(
|
||||||
SELECT appid
|
select
|
||||||
,user_id
|
appid,gm.name as app_name,account,name_abbr,channel,event_time,user_id,ds
|
||||||
,amount / 100 AS pay_amount
|
from public.ods_newly_account acc
|
||||||
FROM public.ods_payment_order
|
inner join
|
||||||
WHERE ds BETWEEN '${bizmonth}' AND '${bizdate}'
|
|
||||||
AND status = 1
|
|
||||||
)
|
|
||||||
,aa AS
|
|
||||||
(
|
(
|
||||||
SELECT appid
|
select id,name,bind_game_id,a.account,b.name_abbr
|
||||||
,user_id
|
from public.gm_apply a
|
||||||
FROM public.ods_active_account
|
left join public.dim_gm_info b on a.account=b.account
|
||||||
WHERE ds BETWEEN '${bizmonth}' AND '${bizdate}'
|
where bind_game_type=1
|
||||||
)
|
) gm on acc.appid=gm.id
|
||||||
INSERT INTO
|
|
||||||
datasci.ads_996eco_index_box_m (index_type,data_month,is_box,act_cnt,pay_cnt,pay_amount)
|
|
||||||
SELECT 'pay' AS index_type
|
|
||||||
,'${month}' data_month
|
|
||||||
,t1.is_box
|
|
||||||
,t1.act_cnt
|
|
||||||
,t2.pay_cnt
|
|
||||||
,t2.pay_amount
|
|
||||||
FROM (
|
|
||||||
SELECT CASE WHEN bu.user_id IS NOT NULL THEN '盒子'
|
|
||||||
ELSE '非盒子'
|
|
||||||
END AS is_box
|
|
||||||
,UNIQ(aa.user_id) AS act_cnt
|
|
||||||
FROM aa
|
|
||||||
INNER JOIN ga
|
|
||||||
ON aa.appid = ga.id
|
|
||||||
LEFT JOIN box_users bu
|
|
||||||
ON bu.user_id = aa.user_id
|
|
||||||
GROUP BY 1
|
|
||||||
) t1
|
|
||||||
LEFT JOIN (
|
|
||||||
SELECT CASE WHEN bu.user_id IS NOT NULL THEN '盒子'
|
|
||||||
ELSE '非盒子'
|
|
||||||
END AS is_box
|
|
||||||
,UNIQ(po.user_id) AS pay_cnt
|
|
||||||
,SUM(po.pay_amount) AS pay_amount
|
|
||||||
FROM po
|
|
||||||
INNER JOIN ga
|
|
||||||
ON po.appid = ga.id
|
|
||||||
LEFT JOIN box_users bu
|
|
||||||
ON bu.user_id = po.user_id
|
|
||||||
GROUP BY 1
|
|
||||||
) t2
|
|
||||||
ON t1.is_box = t2.is_box
|
|
||||||
;
|
|
||||||
|
|
||||||
-- mau
|
|
||||||
WITH game_apply AS
|
|
||||||
(
|
|
||||||
SELECT id
|
|
||||||
,name
|
|
||||||
,bind_game_id
|
|
||||||
FROM public.gm_apply
|
|
||||||
WHERE bind_game_type = 1
|
|
||||||
)
|
|
||||||
INSERT INTO
|
|
||||||
datasci.ads_996eco_index_box_m (index_type,data_month,is_box,mau)
|
|
||||||
SELECT 'mau' index_type
|
|
||||||
,'${month}' data_month
|
|
||||||
,CASE WHEN grouping(user_flag) = 0 THEN user_flag
|
|
||||||
ELSE '总计'
|
|
||||||
END AS is_box
|
|
||||||
,uniq(user_id) AS mau
|
|
||||||
FROM (
|
|
||||||
SELECT CASE WHEN t1.channel LIKE '%996box%' THEN '盒子'
|
|
||||||
ELSE '非盒子'
|
|
||||||
END AS user_flag
|
|
||||||
,user_id
|
|
||||||
FROM public.ods_active_account t1
|
|
||||||
INNER JOIN game_apply t2
|
|
||||||
ON t1.appid = t2.id
|
|
||||||
WHERE t1.ds BETWEEN '${hisdate}' AND '${bizdate}'
|
|
||||||
) t
|
) t
|
||||||
GROUP BY user_flag
|
) t1
|
||||||
;
|
left join datasci.dws_plt_newly_account_d t2 on t1.user_id=t2.user_id
|
||||||
|
where rn=1
|
||||||
-- mau-device
|
and t1.ds between '${hisdate}' and '${bizdate}'
|
||||||
WITH game_apply AS
|
--and user_id='1419067566'
|
||||||
|
),
|
||||||
|
retention_active_detail as
|
||||||
(
|
(
|
||||||
SELECT id
|
select
|
||||||
,name
|
ds::date as dt,user_id
|
||||||
,bind_game_id
|
from public.ods_active_account t1
|
||||||
FROM public.gm_apply
|
inner join
|
||||||
WHERE bind_game_type = 1
|
(
|
||||||
|
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
|
||||||
|
(
|
||||||
|
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'
|
||||||
)
|
)
|
||||||
INSERT INTO
|
--渠道留存
|
||||||
datasci.ads_996eco_index_box_m (index_type,data_month,is_box,device_type,device_type_new,act_num)
|
select
|
||||||
SELECT 'mau-device' index_type
|
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
|
||||||
,'${month}' AS data_month
|
from
|
||||||
,CASE WHEN t1.channel LIKE '%996box%' THEN '盒子'
|
(
|
||||||
ELSE '非盒子'
|
select
|
||||||
END AS is_box
|
user_flag,new_acc_dt,uniq(user_id) as new_user_num
|
||||||
,t1.device_type
|
from retention_rd
|
||||||
,CASE WHEN lower(t1.device_type) LIKE '%h5%' THEN 'H5'
|
where rd=0
|
||||||
WHEN lower(t1.device_type) LIKE '%pc%' THEN 'PC'
|
group by
|
||||||
WHEN lower(t1.device_type) LIKE '%ios%' THEN 'IOS'
|
user_flag,new_acc_dt
|
||||||
ELSE t1.device_type
|
) t1
|
||||||
END AS device_type_new
|
left join
|
||||||
,uniq(user_id) AS act_num
|
(
|
||||||
FROM public.ods_active_account t1
|
select
|
||||||
INNER JOIN game_apply t2
|
user_flag,new_acc_dt,
|
||||||
ON t1.appid = t2.id
|
uniq(case when rd=1 then user_id else null end) as ret_1,
|
||||||
WHERE t1.ds BETWEEN '${hisdate}' AND '${bizdate}'
|
uniq(case when rd=7 then user_id else null end) as ret_7,
|
||||||
GROUP BY 1,2,3,4
|
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
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
-- reg
|
|
||||||
WITH legend_apps AS
|
|
||||||
(
|
|
||||||
SELECT id AS appid
|
|
||||||
FROM gm_apply
|
|
||||||
WHERE bind_game_type = 1
|
|
||||||
AND bind_type = 1 -- 默认应用
|
|
||||||
)
|
|
||||||
---传奇游戏
|
|
||||||
,tmp_ods_newly_account AS
|
|
||||||
(
|
|
||||||
SELECT *
|
|
||||||
FROM ods_newly_account
|
|
||||||
WHERE ds BETWEEN '${hisdate}' AND '${bizdate}'
|
|
||||||
)
|
|
||||||
,box_users AS
|
|
||||||
(
|
|
||||||
SELECT user_id
|
|
||||||
FROM tmp_ods_newly_account
|
|
||||||
WHERE appid = 1015
|
|
||||||
OR channel ~ '996box'
|
|
||||||
OR channel IN (
|
|
||||||
SELECT value AS channel
|
|
||||||
FROM public.dws_app_props
|
|
||||||
WHERE appid = 1015
|
|
||||||
AND prop = 2
|
|
||||||
)
|
|
||||||
GROUP BY user_id
|
|
||||||
)
|
|
||||||
-- 筛选出有盒子记录以及玩过传奇游戏的玩家
|
|
||||||
,box_users_with_legend AS
|
|
||||||
(
|
|
||||||
SELECT acc.user_id
|
|
||||||
FROM tmp_ods_newly_account acc
|
|
||||||
WHERE
|
|
||||||
EXISTS(
|
|
||||||
SELECT 1
|
|
||||||
FROM legend_apps app
|
|
||||||
WHERE acc.appid = app.appid
|
|
||||||
)
|
|
||||||
AND
|
|
||||||
EXISTS(
|
|
||||||
SELECT 1
|
|
||||||
FROM box_users box
|
|
||||||
WHERE box.user_id = acc.user_id
|
|
||||||
)
|
|
||||||
)
|
|
||||||
,reg_account AS
|
|
||||||
(
|
|
||||||
-- 普通用户的传奇记录
|
|
||||||
SELECT acc.gmid
|
|
||||||
,acc.appid
|
|
||||||
,acc.channel
|
|
||||||
,acc.user_id
|
|
||||||
,acc.device_type
|
|
||||||
,acc.event_time
|
|
||||||
,acc.ds
|
|
||||||
,'非盒子用户' AS user_flag --表示没有玩过盒子的普通传奇用户
|
|
||||||
,'0' AS sub_channel
|
|
||||||
FROM tmp_ods_newly_account acc
|
|
||||||
WHERE
|
|
||||||
EXISTS(
|
|
||||||
SELECT 1
|
|
||||||
FROM legend_apps app
|
|
||||||
WHERE app.appid = acc.appid
|
|
||||||
)
|
|
||||||
AND NOT
|
|
||||||
EXISTS(
|
|
||||||
SELECT 1
|
|
||||||
FROM box_users box
|
|
||||||
WHERE box.user_id = acc.user_id
|
|
||||||
)
|
|
||||||
UNION ALL -- 盒子用户玩过传奇的全量记录
|
|
||||||
SELECT acc.gmid
|
|
||||||
,acc.appid
|
|
||||||
,CASE WHEN bxchl.channel_desc IS NOT NULL THEN bxchl.channel_desc
|
|
||||||
ELSE acc.channel
|
|
||||||
END AS channel
|
|
||||||
,acc.user_id
|
|
||||||
,acc.device_type
|
|
||||||
,acc.event_time
|
|
||||||
,acc.ds
|
|
||||||
,'盒子用户' AS user_flag ---表示玩过盒子的用户
|
|
||||||
,bxchl.channel_desc AS sub_channel
|
|
||||||
FROM tmp_ods_newly_account acc
|
|
||||||
LEFT JOIN (
|
|
||||||
SELECT appid
|
|
||||||
,value AS channel
|
|
||||||
,ext AS channel_desc
|
|
||||||
FROM public.dws_app_props
|
|
||||||
WHERE appid = 1015
|
|
||||||
AND prop = 2 -- and length(ext)>0
|
|
||||||
) bxchl
|
|
||||||
ON acc.appid = bxchl.appid
|
|
||||||
AND acc.channel = bxchl.channel
|
|
||||||
WHERE
|
|
||||||
EXISTS(
|
|
||||||
SELECT 1
|
|
||||||
FROM box_users_with_legend b
|
|
||||||
WHERE b.user_id = acc.user_id
|
|
||||||
)
|
|
||||||
)
|
|
||||||
INSERT INTO
|
|
||||||
datasci.ads_996eco_index_box_m (index_type,data_month,is_box,reg_count)
|
|
||||||
SELECT 'reg' index_type
|
|
||||||
,'${month}' AS data_month
|
|
||||||
,CASE WHEN user_flag = '非盒子用户' THEN '非盒子注册用户'
|
|
||||||
WHEN user_flag = '盒子用户'
|
|
||||||
AND (appid = 1015
|
|
||||||
OR channel ~ '996box'
|
|
||||||
OR sub_channel IS NOT NULL) THEN '盒子注册用户'
|
|
||||||
ELSE '非盒子注册用户'
|
|
||||||
END AS is_box
|
|
||||||
,uniq(mi.user_id) AS reg_count
|
|
||||||
FROM reg_account acc
|
|
||||||
INNER JOIN (
|
|
||||||
SELECT user_id
|
|
||||||
,MIN(event_time) AS event_time_min
|
|
||||||
FROM reg_account
|
|
||||||
GROUP BY user_id
|
|
||||||
) mi ---从玩家的众多游戏记录中选取最早的一条
|
|
||||||
ON acc.user_id = mi.user_id
|
|
||||||
AND acc.event_time = mi.event_time_min
|
|
||||||
GROUP BY 1
|
|
||||||
,2
|
|
||||||
,3
|
|
||||||
;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
141
996eco/ads_996eco_index_ltv_d.sql
Normal file
141
996eco/ads_996eco_index_ltv_d.sql
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
--bizdate 20250431 bizmonth 20250401 bizmonth
|
||||||
|
|
||||||
|
CREATE TABLE datasci.ads_996eco_index_ltv_d (
|
||||||
|
index_type text,
|
||||||
|
data_day text,
|
||||||
|
is_box text,
|
||||||
|
acc_count bigint,
|
||||||
|
ltv0 bigint,
|
||||||
|
ltv1 bigint,
|
||||||
|
ltv2 bigint,
|
||||||
|
ltv3 bigint,
|
||||||
|
ltv4 bigint,
|
||||||
|
ltv5 bigint,
|
||||||
|
ltv6 bigint,
|
||||||
|
ltv7 bigint,
|
||||||
|
ltv8 bigint,
|
||||||
|
ltv9 bigint,
|
||||||
|
ltv10 bigint,
|
||||||
|
ltv11 bigint,
|
||||||
|
ltv12 bigint,
|
||||||
|
ltv13 bigint,
|
||||||
|
ltv14 bigint,
|
||||||
|
ltv15 bigint,
|
||||||
|
ltv16 bigint,
|
||||||
|
ltv17 bigint,
|
||||||
|
ltv18 bigint,
|
||||||
|
ltv19 bigint,
|
||||||
|
ltv20 bigint,
|
||||||
|
ltv21 bigint,
|
||||||
|
ltv22 bigint,
|
||||||
|
ltv23 bigint,
|
||||||
|
ltv24 bigint,
|
||||||
|
ltv25 bigint,
|
||||||
|
ltv26 bigint,
|
||||||
|
ltv27 bigint,
|
||||||
|
ltv28 bigint,
|
||||||
|
ltv29 bigint,
|
||||||
|
ltv30 bigint,
|
||||||
|
ltv31 bigint,
|
||||||
|
ltv45 bigint,
|
||||||
|
ltv60 bigint,
|
||||||
|
ltv90 bigint,
|
||||||
|
ltv120 bigint
|
||||||
|
);
|
||||||
|
|
||||||
|
DELETE FROM datasci.ads_996eco_index_ltv_d WHERE 1=1;
|
||||||
|
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
with retention_new_acc as
|
||||||
|
(
|
||||||
|
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
|
||||||
|
) t
|
||||||
|
) 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
|
||||||
|
(
|
||||||
|
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
|
||||||
|
(
|
||||||
|
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'
|
||||||
|
)
|
||||||
|
--渠道留存
|
||||||
|
SELECT
|
||||||
|
'is_box_ltv' index_type,
|
||||||
|
t1.new_acc_dt data_day,
|
||||||
|
t1.user_flag is_box,
|
||||||
|
t1.new_user_num acc_count,
|
||||||
|
t2.ret_1 ltv1,
|
||||||
|
ret_7 ltv7,
|
||||||
|
ret_14 ltv14,
|
||||||
|
ret_30 ltv30,
|
||||||
|
ret_60 ltv60,
|
||||||
|
ret_90 ltv90,
|
||||||
|
ret_180 ltv180
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
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
|
||||||
|
(
|
||||||
|
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
|
||||||
|
;
|
||||||
|
|
1518
996eco/ads_996eco_index_ltv_m.sql
Normal file
1518
996eco/ads_996eco_index_ltv_m.sql
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user