提交3
This commit is contained in:
parent
a85c3cbd2f
commit
5f096b2d69
@ -62,8 +62,9 @@ CREATE TABLE public.tbl_col (
|
|||||||
|
|
||||||
primary key 主键
|
primary key 主键
|
||||||
distribution_key 分布
|
distribution_key 分布
|
||||||
event_time_column 单调递增或单调递减的有序字段
|
|
||||||
clustering_key Cluster Filter算子,表明命中了Clustering Key
|
clustering_key Cluster Filter算子,表明命中了Clustering Key
|
||||||
|
event_time_column 单调递增或单调递减的有序字段
|
||||||
dictionary_encoding_columns字典编码
|
dictionary_encoding_columns字典编码
|
||||||
bitmap_columns 位图索引
|
bitmap_columns 位图索引
|
||||||
|
|
||||||
@ -102,4 +103,55 @@ relminmxid:最小的多事务ID,当所有旧的MXID都过期时更新。
|
|||||||
relacl:该关系的访问权限列表。
|
relacl:该关系的访问权限列表。
|
||||||
reloptions:该关系的选项列表。
|
reloptions:该关系的选项列表。
|
||||||
relpartbound:如果是分区表,此字段包含定义其边界条件的信息
|
relpartbound:如果是分区表,此字段包含定义其边界条件的信息
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SELECT * FROM hg_table_storage_status('<schema_name>', '<table_name>');
|
||||||
|
|
||||||
|
alter table A rename to B;
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
hg_table_storage_status ('datasci', 'dwd_track_log_no_resc_d')
|
||||||
|
WHERE
|
||||||
|
table_name >= 'dwd_track_log_no_resc_d_20250201'
|
||||||
|
-- AND table_name < 'dwd_track_log_no_resc_d_20250506'
|
||||||
|
ORDER BY
|
||||||
|
table_name;
|
||||||
|
|
||||||
|
|
||||||
|
CALL set_table_property('datasci.dwd_track_log_no_resc_d_20241106', 'storage_mode', 'hot');
|
||||||
|
|
||||||
|
CALL set_table_property('tbl_p', 'auto_partitioning.num_hot', '4');
|
||||||
|
|
||||||
|
ALTER TABLE datasci.ads_996eco_index_ltv_m
|
||||||
|
ADD COLUMN tg_value TEXT;
|
||||||
|
ALTER TABLE datasci.ads_996eco_index_ltv_m
|
||||||
|
ADD COLUMN new_cnt bigint;
|
||||||
|
|
||||||
|
ALTER TABLE dws_role_apply_payment_tag_d DROP IF EXISTS PARTITION (ds < '20250603');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
WITH data AS (
|
||||||
|
SELECT '20250101' ds, 'a' c_1, 'b' c_2, 'c' c_3, 1 c_4, 2 c_5
|
||||||
|
),
|
||||||
|
-- 转换 c_1, c_2, c_3 到 value1
|
||||||
|
unpivot_str AS (
|
||||||
|
SELECT ds, type, value AS value1, NULL AS value2
|
||||||
|
FROM data
|
||||||
|
UNPIVOT (value FOR type IN (c_1, c_2, c_3))
|
||||||
|
),
|
||||||
|
-- 转换 c_4, c_5 到 value2
|
||||||
|
unpivot_num AS (
|
||||||
|
SELECT ds, type, NULL AS value1, value AS value2
|
||||||
|
FROM data
|
||||||
|
UNPIVOT (value FOR type IN (c_4, c_5))
|
||||||
|
)
|
||||||
|
-- 合并结果
|
||||||
|
SELECT * FROM unpivot_str
|
||||||
|
UNION ALL
|
||||||
|
SELECT * FROM unpivot_num;
|
74
996/Hologres/元数据.sql
Normal file
74
996/Hologres/元数据.sql
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
SELECT A .oid, A .relname AS NAME, b.description AS COMMENT FROM pg_class A LEFT OUTER JOIN pg_description b ON b.objsubid = 0 AND A .oid = b.objoid
|
||||||
|
WHERE A .relnamespace = ( SELECT oid FROM pg_namespace WHERE nspname = 'public' ) AND A .relkind = 'r' ORDER BY A .relname
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
-- 普通表非分区表数据
|
||||||
|
select *
|
||||||
|
FROM pg_class A
|
||||||
|
WHERE A .relnamespace = ( SELECT oid FROM pg_namespace WHERE nspname = 'public' ) -- 空间是 public
|
||||||
|
AND A .relkind = 'r' -- 关系的类型,可以是普通表('r')、索引('i')、序列('S')、视图('v')、物化视图('m')、组合类型('c')、外部表('f')、分区表('p')
|
||||||
|
AND relpartbound is NULL -- 非分区表
|
||||||
|
|
||||||
|
-- 分区表主表数据
|
||||||
|
select *
|
||||||
|
FROM pg_class A
|
||||||
|
WHERE A .relnamespace = ( SELECT oid FROM pg_namespace WHERE nspname = 'public' ) -- 空间是 public
|
||||||
|
AND A .relkind = 'p' -- 关系的类型,可以是普通表('r')、索引('i')、序列('S')、视图('v')、物化视图('m')、组合类型('c')、外部表('f')、分区表('p')
|
||||||
|
AND relpartbound is NULL -- 非分区表
|
||||||
|
|
||||||
|
|
||||||
|
select reltuples -- 表记录数
|
||||||
|
FROM pg_class A where relname='ods_track_log_20241107'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- 普通表非分区表数据
|
||||||
|
select 'sdk_statis_test' databases,'public' nspname,relname table_name,relkind table_type,relhassubclass relhassubclass,'' son_table
|
||||||
|
FROM pg_class t1
|
||||||
|
WHERE t1.relnamespace = ( SELECT oid FROM pg_namespace WHERE nspname = 'public' ) -- 空间是 public
|
||||||
|
AND t1.relkind = 'r' -- 关系的类型,可以是普通表('r')、索引('i')、序列('S')、视图('v')、物化视图('m')、组合类型('c')、外部表('f')、分区表('p')
|
||||||
|
AND relpartbound is NULL -- 非分区表
|
||||||
|
UNION
|
||||||
|
-- 分区表主表数据
|
||||||
|
select 'sdk_statis_test' databases,'public' nspname,relname table_name,relkind table_type,relhassubclass relhassubclass,'' son_table
|
||||||
|
FROM pg_class t1
|
||||||
|
WHERE t1.relnamespace = ( SELECT oid FROM pg_namespace WHERE nspname = 'public' ) -- 空间是 public
|
||||||
|
AND t1.relkind = 'p' -- 关系的类型,可以是普通表('r')、索引('i')、序列('S')、视图('v')、物化视图('m')、组合类型('c')、外部表('f')、分区表('p')
|
||||||
|
and t1.relhassubclass!='t'
|
||||||
|
|
||||||
|
UNION
|
||||||
|
select
|
||||||
|
databases ,nspname, table_name, table_type, relhassubclass, string_agg(son_table, ',') AS son_table
|
||||||
|
from
|
||||||
|
(
|
||||||
|
select 'sdk_statis_test' databases,'public' nspname,t1.relname table_name,t1.relkind table_type,t1.relhassubclass relhassubclass,t3.relname son_table
|
||||||
|
FROM pg_class t1
|
||||||
|
JOIN pg_inherits t2
|
||||||
|
on t1.oid=t2.inhparent
|
||||||
|
JOIN pg_class t3
|
||||||
|
on t2.inhrelid = t3.oid
|
||||||
|
WHERE t1.relnamespace = ( SELECT oid FROM pg_namespace WHERE nspname = 'public' ) -- 空间是 public
|
||||||
|
AND t1.relkind = 'p' -- 关系的类型,可以是普通表('r')、索引('i')、序列('S')、视图('v')、物化视图('m')、组合类型('c')、外部表('f')、分区表('p')
|
||||||
|
and t1.relhassubclass='t'
|
||||||
|
) t4
|
||||||
|
group by databases ,nspname, table_name, table_type, relhassubclass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
count(1) zs
|
||||||
|
FROM
|
||||||
|
ods.track_log_037 a
|
||||||
|
WHERE
|
||||||
|
a.ds BETWEEN '20240829' AND '20241125'
|
||||||
|
|
||||||
|
select concat(E'union all select count(*) zs, \'' ,relname, E'\' tablename from ods.',relname,E' where ds BETWEEN \'20241118\' AND \'20241125\' ') sql_str
|
||||||
|
FROM pg_class A
|
||||||
|
WHERE A .relnamespace = ( SELECT oid FROM pg_namespace WHERE nspname = 'ods' ) -- 空间是 public
|
||||||
|
AND A .relkind = 'p' -- 关系的类型,可以是普通表('r')、索引('i')、序列('S')、视图('v')、物化视图('m')、组合类型('c')、外部表('f')、分区表('p')
|
||||||
|
AND relpartbound is NULL
|
||||||
|
|
||||||
|
|
||||||
|
|
102
996eco/1.sql
102
996eco/1.sql
@ -1,97 +1,7 @@
|
|||||||
with retention_new_acc as
|
|
||||||
(
|
|
||||||
select
|
|
||||||
appid,app_name,channel,bind_game_id,
|
|
||||||
event_time,user_id,ds::date as new_acc_dt
|
|
||||||
from
|
|
||||||
(
|
|
||||||
select
|
|
||||||
bind_game_id,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,channel,event_time,user_id,ds,gm.bind_game_id
|
|
||||||
from public.ods_newly_account acc
|
|
||||||
inner join
|
|
||||||
(
|
|
||||||
select id,name,bind_game_id
|
|
||||||
from public.gm_apply
|
|
||||||
where bind_game_type=1
|
|
||||||
) gm on acc.appid=gm.id
|
|
||||||
) t
|
|
||||||
) t1
|
|
||||||
where rn=1
|
|
||||||
and 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
|
|
||||||
appid,app_name,channel,tg_play.tag as tg_play,tg_ver.tag as tg_ver,tg_value.tag as tg_value,tg_job.tag as tg_job,tg_feature.tag as tg_feature,
|
|
||||||
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 outer join
|
|
||||||
(select game_id,tag from public.game_tags where tag in ('神器','复古','沉默','火龙','合击','迷失','小极品','大极品','二合一','铭文','冰雪','宠物','战神','暗黑','元素','忘忧','BUFF','天罡'))tg_play
|
|
||||||
on t1.bind_game_id=tg_play.game_id
|
|
||||||
left outer join
|
|
||||||
(select game_id,tag from public.game_tags where tag in ('1.70','1.76','1.80','1.85','1.95'))tg_ver
|
|
||||||
on t1.bind_game_id=tg_ver.game_id
|
|
||||||
left outer join
|
|
||||||
(select game_id,tag from public.game_tags where tag in ('经典','微变','中变','超变'))tg_value
|
|
||||||
on t1.bind_game_id=tg_value.game_id
|
|
||||||
left outer join
|
|
||||||
(select game_id,tag from public.game_tags where tag in ('单职业','三职业','多职业'))tg_job
|
|
||||||
on t1.bind_game_id=tg_job.game_id
|
|
||||||
left outer join
|
|
||||||
(select game_id,tag from public.game_tags where tag in ('3D','开服1年','开服2年','开服3年','开服4年'))tg_feature
|
|
||||||
on t1.bind_game_id=tg_feature.game_id
|
|
||||||
where t2.dt-t1.new_acc_dt in (0,1,7,14,30,60,90,180)
|
|
||||||
--t1.user_id='1419067566'
|
|
||||||
)
|
|
||||||
|
|
||||||
select
|
|
||||||
t1.tg_play,t1.tg_ver,t1.tg_value,t1.tg_job,t1.tg_feature,t1.new_acc_mon,t1.new_user_num,t2.ret_1,ret_7,ret_14,ret_30,ret_60,ret_90,ret_180
|
注册账号到创角转化率 创角转换率 ads_industry_create_role_rate_d
|
||||||
from
|
注册账号24小时内破冰率 游戏24小时破冰率 ads_industry_ice_break_rate_d
|
||||||
(
|
游戏时长次留率-50分钟以上游戏次留率 游戏50分钟以上留存 ads_industry_50_min_retention_d
|
||||||
select
|
游戏时长-5分钟内角色数&占比 游戏5分钟内角色占比 ads_industry_role_ratio_d
|
||||||
coalesce(tg_play,'未知') as tg_play,coalesce(tg_ver,'未知') as tg_ver,coalesce(tg_value,'未知') as tg_value,coalesce(tg_job,'未知') as tg_job,coalesce(tg_feature,'未知') as tg_feature,
|
次日留存率/7日留存/15日留存/30日留存 新账户留存 ads_industry_new_acc_retention_d
|
||||||
date_trunc('month',new_acc_dt) as new_acc_mon,uniq(user_id) as new_user_num
|
|
||||||
from retention_rd
|
|
||||||
where rd=0
|
|
||||||
group by
|
|
||||||
coalesce(tg_play,'未知') ,coalesce(tg_ver,'未知') ,coalesce(tg_value,'未知') ,coalesce(tg_job,'未知') ,coalesce(tg_feature,'未知'),date_trunc('month',new_acc_dt)
|
|
||||||
) t1
|
|
||||||
left join
|
|
||||||
(
|
|
||||||
select
|
|
||||||
coalesce(tg_play,'未知') as tg_play,coalesce(tg_ver,'未知') as tg_ver,coalesce(tg_value,'未知') as tg_value,coalesce(tg_job,'未知') as tg_job,
|
|
||||||
coalesce(tg_feature,'未知') as tg_feature,date_trunc('month',new_acc_dt) as new_acc_mon,
|
|
||||||
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
|
|
||||||
coalesce(tg_play,'未知') ,coalesce(tg_ver,'未知') ,coalesce(tg_value,'未知') ,coalesce(tg_job,'未知') ,coalesce(tg_feature,'未知'),date_trunc('month',new_acc_dt)
|
|
||||||
) t2 on t1.new_acc_mon=t2.new_acc_mon and t1.tg_play=t2.tg_play and t1.tg_ver=t2.tg_ver and t1.tg_value=t2.tg_value and t1.tg_job=t2.tg_job and t1.tg_feature=t2.tg_feature
|
|
||||||
limit 10000
|
|
||||||
|
105
996eco/2.sql
105
996eco/2.sql
@ -1,31 +1,74 @@
|
|||||||
-- 也优化不了
|
CREATE TABLE datasci.ads_industry_new_acc_retention_d (
|
||||||
select to_char(to_timestamp(event_time_min), 'YYYY-MM') as reg_month,
|
ds text NOT NULL,
|
||||||
DATE_TRUNC('month', to_timestamp(event_time_min)) as reg_month_date,
|
tag text NOT NULL,
|
||||||
case when tg_play.tag is null then '未知' else tg_play.tag end as play_tag,
|
ret1_avg numeric(10,4),
|
||||||
uniq(mi.user_id) as acc_count
|
ret1_50 numeric(10,4),
|
||||||
from public.ods_newly_account acc
|
ret1_70 numeric(10,4),
|
||||||
inner join (select user_id, min(event_time) as event_time_min
|
ret1_80 numeric(10,4),
|
||||||
from public.ods_newly_account acc
|
ret1_90 numeric(10,4),
|
||||||
inner join (select *
|
ret7_avg numeric(10,4),
|
||||||
from public.gm_apply
|
ret7_50 numeric(10,4),
|
||||||
WHERE bind_game_type = 1 -- 传奇游戏
|
ret7_70 numeric(10,4),
|
||||||
) app
|
ret7_80 numeric(10,4),
|
||||||
on acc.appid = app.id
|
ret7_90 numeric(10,4),
|
||||||
group by user_id) mi ---从玩家的众多游戏记录中选取最早的一条
|
ret15_avg numeric(10,4),
|
||||||
on acc.user_id = mi.user_id and acc.event_time = mi.event_time_min
|
ret15_50 numeric(10,4),
|
||||||
inner join (SELECT id as app_id,
|
ret15_70 numeric(10,4),
|
||||||
name as app_name,
|
ret15_80 numeric(10,4),
|
||||||
bind_game_id,
|
ret15_90 numeric(10,4),
|
||||||
bind_game_type ---1 :传奇游戏 , 2:传世 , 3:传3
|
ret30_avg numeric(10,4),
|
||||||
FROM public.gm_apply
|
ret30_50 numeric(10,4),
|
||||||
WHERE bind_type = 1 -- 默认应用
|
ret30_70 numeric(10,4),
|
||||||
) gm
|
ret30_80 numeric(10,4),
|
||||||
on acc.appid = gm.app_id
|
ret30_90 numeric(10,4),
|
||||||
left outer join
|
PRIMARY KEY (ds, tag)
|
||||||
(select game_id, tag
|
)
|
||||||
from public.game_tags
|
|
||||||
where tag in
|
CREATE TABLE datasci.ads_industry_role_ratio_d (
|
||||||
('神器', '复古', '沉默', '火龙', '合击', '迷失', '小极品', '大极品', '二合一', '铭文', '冰雪', '宠物',
|
ds text NOT NULL,
|
||||||
'战神', '暗黑', '元素', '忘忧', 'BUFF', '天罡')) tg_play
|
tag text NOT NULL,
|
||||||
on gm.bind_game_id = tg_play.game_id
|
proportion_5min_role_avg numeric(10,4),
|
||||||
group by 1, 2, 3 limit 10000
|
proportion_5min_role_50 numeric(10,4),
|
||||||
|
proportion_5min_role_70 numeric(10,4),
|
||||||
|
proportion_5min_role_80 numeric(10,4),
|
||||||
|
proportion_5min_role_90 numeric(10,4),
|
||||||
|
PRIMARY KEY (ds, tag)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
CREATE TABLE datasci.ads_industry_50_min_retention_d (
|
||||||
|
ds text NOT NULL,
|
||||||
|
tag text NOT NULL,
|
||||||
|
proportion_ret1_50min_role_avg numeric(10,4),
|
||||||
|
proportion_ret1_50min_role_50 numeric(10,4),
|
||||||
|
proportion_ret1_50min_role_70 numeric(10,4),
|
||||||
|
proportion_ret1_50min_role_80 numeric(10,4),
|
||||||
|
proportion_ret1_50min_role_90 numeric(10,4),
|
||||||
|
PRIMARY KEY (ds, tag)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
CREATE TABLE datasci.ads_industry_ice_break_rate_d (
|
||||||
|
ds text NOT NULL,
|
||||||
|
tag text NOT NULL,
|
||||||
|
rate_role_pay_avg numeric(10,4),
|
||||||
|
rate_role_pay_50 numeric(10,4),
|
||||||
|
rate_role_pay_70 numeric(10,4),
|
||||||
|
rate_role_pay_80 numeric(10,4),
|
||||||
|
rate_role_pay_90 numeric(10,4),
|
||||||
|
PRIMARY KEY (ds, tag)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
CREATE TABLE datasci.ads_industry_create_role_rate_d (
|
||||||
|
ds text NOT NULL,
|
||||||
|
tag text NOT NULL,
|
||||||
|
rate_role_create_avg numeric(10,4),
|
||||||
|
rate_role_create_50 numeric(10,4),
|
||||||
|
rate_role_create_70 numeric(10,4),
|
||||||
|
rate_role_create_80 numeric(10,4),
|
||||||
|
rate_role_create_90 numeric(10,4),
|
||||||
|
PRIMARY KEY (ds, tag)
|
||||||
|
)
|
376
996eco/3.sql
Normal file
376
996eco/3.sql
Normal file
@ -0,0 +1,376 @@
|
|||||||
|
|
||||||
|
DELETE FROM datasci.ads_996eco_index_ltv_m WHERE index_type='coop_ltv';
|
||||||
|
|
||||||
|
-- coop_ltv
|
||||||
|
-------------------- pending
|
||||||
|
-- 可以优化
|
||||||
|
with retention_new_acc as
|
||||||
|
(
|
||||||
|
select
|
||||||
|
appid,app_name,
|
||||||
|
case when channel~'盒子' or channel~'996box' then '盒子'
|
||||||
|
when account in ('wanxin996','qqq492864156','yueyou996') then '玩心'
|
||||||
|
when account in ('13234701199', 'xiongDiwan', 'xiongdi996', '996xiongdi', 'cly225522') then '春秋玩'
|
||||||
|
when account in ('tuantuan6400','whtuantuan','whzhangyou','whzhangyou1') then '安峰'
|
||||||
|
when account in ('Jinri', 'zhangqian996') THEN '掌玩'
|
||||||
|
when account='zlkj996' then '智灵'
|
||||||
|
when account='ssyy1' then '盈优'
|
||||||
|
when account in ('ky6709') then '恺英'
|
||||||
|
when account in ('hzxs0375') then '勋双'
|
||||||
|
when account in ('nb1290733693','9377yyeb','9377syybyy') then '9377'
|
||||||
|
when account in ('tanwangm', 'tanwan996', 'tw996hz99', 'tw996hz66', 'tanlang996', '15868405282', 'tanwanjx') then '贪玩'
|
||||||
|
when account in ('longxiang','zhanxingbo','18659080001') then '龙翔'
|
||||||
|
when account in ('13216396033','Zwzb2024','YP2024') then '玉盘'
|
||||||
|
when account in ('chongqu001','18968060998') and app_name ~ '【宠趣.*】|【87.*】' then '宠趣'
|
||||||
|
when account in ('youyi888','youyi999') and app_name ~ '【YY.*】|【游奕.*】' then '游奕'
|
||||||
|
when account in ('jinrui','huiqi996','996mailiang','huiqi2996') then '慧跃'
|
||||||
|
when app_name ~ '【.*?联运' then REGEXP_REPLACE(app_name, '.*【(.*?)联运.*', '\1')
|
||||||
|
when app_name !~ '【.*?联运' and app_name ~ '.*【(.*?)】.*' then REGEXP_REPLACE(app_name, '.*【(.*?)】.*', '\1')
|
||||||
|
else '其他' end as co_oper_partner,
|
||||||
|
case when channel~'盒子' or channel~'996box' then '盒子'
|
||||||
|
when channel~'ai6' then 'ai6'
|
||||||
|
when channel~'玩心' then '玩心'
|
||||||
|
when channel~'应用宝' then '应用宝'
|
||||||
|
when channel~'纸片' then '纸片'
|
||||||
|
when channel~'团团' then '团团'
|
||||||
|
when channel~'335玩' then '335玩'
|
||||||
|
when channel~'朋克' then '朋克'
|
||||||
|
when channel~'安徽追游' then '安徽追游'
|
||||||
|
when channel~'冰火' then '冰火'
|
||||||
|
when channel~'心乐' then '心乐'
|
||||||
|
when channel ~*'华为|vivo|oppo|魅族|努比亚|联想|酷派|硬核联盟' then '硬核联盟'
|
||||||
|
when channel~'9377' then '9377'
|
||||||
|
when channel~'智灵' then '智灵'
|
||||||
|
when channel~'掌游' then '掌游'
|
||||||
|
when channel~'上士' then '上士'
|
||||||
|
when channel~'攒趣' then '攒趣'
|
||||||
|
when channel~'掌玩' then '掌玩'
|
||||||
|
when channel~'贪玩' then '贪玩'
|
||||||
|
when channel~'wx'or channel~'WX'or channel~'微信' then '微信'
|
||||||
|
when channel~'公众号' then '公众号'
|
||||||
|
when channel~'qq' or channel~'QQ' then 'QQ'
|
||||||
|
--when channel~'quick' then 'quick'
|
||||||
|
when channel~'七牛' then '七牛'
|
||||||
|
when channel~'霸气' then '霸气'
|
||||||
|
when channel~'xy' or channel~'XY' then 'XY'
|
||||||
|
when channel~'芝麻互娱' then '芝麻互娱'
|
||||||
|
when channel~'龙翔' then '龙翔'
|
||||||
|
when channel~'布咕' then '布咕'
|
||||||
|
when channel~'小柠互娱' then '小柠互娱'
|
||||||
|
when channel~'春秋玩' then '春秋玩'
|
||||||
|
when channel~'欢喜时代' then '欢喜时代'
|
||||||
|
when channel~'上游' then '上游'
|
||||||
|
when channel~'倾程' then '倾程'
|
||||||
|
when channel~'绿洲' then '绿洲'
|
||||||
|
when channel~'雷电' then '雷电'
|
||||||
|
when channel~'点点' then '点点'
|
||||||
|
when channel~'小七' then '小七'
|
||||||
|
when channel~'瓜玩' then '瓜玩'
|
||||||
|
when channel~'艺云' then '艺云'
|
||||||
|
when channel~'冠游' then '冠游'
|
||||||
|
when channel~'玄藏' then '玄藏'
|
||||||
|
when channel~'羽龙' then '羽龙'
|
||||||
|
when channel~'星云' then '星云'
|
||||||
|
when channel~'爱尚游' then '爱尚游'
|
||||||
|
when channel~'昊玩' then '昊玩'
|
||||||
|
when channel~'8酷' then '8酷'
|
||||||
|
when channel~'迅玩' then '迅玩'
|
||||||
|
when channel~'星游' then '星游'
|
||||||
|
when channel~'小米' then '小米'
|
||||||
|
when channel~'趣城' then '趣城'
|
||||||
|
when channel~'诺游' then '诺游'
|
||||||
|
when channel~'洛谷' then '洛谷'
|
||||||
|
when channel~'司墨' then '司墨'
|
||||||
|
when channel~'脚印' then '脚印'
|
||||||
|
when channel~'神游' then '神游'
|
||||||
|
when channel~'拓乐' then '拓乐'
|
||||||
|
when channel~'360' then '360'
|
||||||
|
when channel~'日昇' then '日昇'
|
||||||
|
when channel~'触点' then '触点'
|
||||||
|
when channel~'冠游' then '冠游'
|
||||||
|
when channel~'巴兔' then '巴兔'
|
||||||
|
when channel~'天纵' then '天纵'
|
||||||
|
when channel~'早游戏' then '早游戏'
|
||||||
|
when channel~'爱趣' then '爱趣'
|
||||||
|
when channel~'星楠祥' then '星楠祥'
|
||||||
|
when channel~'贪游' then '贪游'
|
||||||
|
when channel~'君游' then '君游'
|
||||||
|
when channel~'996直播间' then '996直播间'
|
||||||
|
when channel~'mumu' then 'mumu'
|
||||||
|
when channel~'吉祥' then '吉祥直播间'
|
||||||
|
when channel~'溪谷' then '溪谷'
|
||||||
|
when channel~'优谷' then '优谷'
|
||||||
|
when channel~'闪趣' then '闪趣'
|
||||||
|
when channel~'8酷' then '8酷'
|
||||||
|
when channel~'抖音' then '抖音'
|
||||||
|
when channel~'斗鱼' then '斗鱼'
|
||||||
|
when channel~'虎牙' then '虎牙'
|
||||||
|
when channel~'巨量' then '巨量'
|
||||||
|
when channel~'快手' then '快手'
|
||||||
|
when channel~'爱奇艺' then '爱奇艺'
|
||||||
|
when channel~'007' then '007'
|
||||||
|
when channel~'圣宏' then '圣宏'
|
||||||
|
when channel~'顺火' then '顺火'
|
||||||
|
when channel~'飞火' then '飞火'
|
||||||
|
when channel~'乐岛' then '乐岛'
|
||||||
|
when channel~'传柒' then '传柒'
|
||||||
|
when channel~'星际' then '星际'
|
||||||
|
when channel~'玖趣' then '玖趣'
|
||||||
|
when channel~*'ku25' then 'ku25'
|
||||||
|
when channel~'8090' then '8090'
|
||||||
|
when channel~*'appstore' then 'AppStore'
|
||||||
|
when channel~'欢娱' then '欢娱'
|
||||||
|
when channel~'逐梦' then '逐梦'
|
||||||
|
when channel~'兴动' then '兴动'
|
||||||
|
when channel~'3733' then '3733'
|
||||||
|
when channel~'第一游戏' then '第一游戏'
|
||||||
|
when channel~'公会' then '公会'
|
||||||
|
when channel~'欢娱' then '欢娱'
|
||||||
|
when channel~'335玩' then '335玩'
|
||||||
|
when channel~*'4yx' then '4yx'
|
||||||
|
when channel~'37' then '37'
|
||||||
|
when channel~'开心' then '开心'
|
||||||
|
when channel~*'ios' or channel~'苹果' then 'ios苹果端具体不详'
|
||||||
|
when channel~'触点' then '触点'
|
||||||
|
when channel~'游码' then '游码'
|
||||||
|
when channel~*'45yx' then '45yx'
|
||||||
|
when channel~'巨量' then '巨量'
|
||||||
|
when channel~'小铃铛' then '小铃铛'
|
||||||
|
when channel~'2345' then '2345'
|
||||||
|
when channel~'梨子' then '梨子'
|
||||||
|
when channel~'麦游' then '麦游'
|
||||||
|
when channel~'群英' then '群英'
|
||||||
|
when channel~'阅文' then '阅文'
|
||||||
|
when channel~*'kopo' then 'kopo'
|
||||||
|
when channel~'创启' then '创启'
|
||||||
|
when channel~'4366' then '4366'
|
||||||
|
when channel~'大楚' then '大楚'
|
||||||
|
when channel~'巅峰' then '巅峰'
|
||||||
|
when channel~'277' then '277'
|
||||||
|
when channel~'112233' then '112233'
|
||||||
|
when channel~'714' then '714'
|
||||||
|
when channel~'4399' then '4399'
|
||||||
|
when channel~'追忆' then '追忆'
|
||||||
|
when channel~*'yy' then 'yy'
|
||||||
|
when channel~'588' then '588'
|
||||||
|
when channel~'八门' then '八门'
|
||||||
|
when channel~*'pdd' then 'pdd'
|
||||||
|
when channel~'9917' then '9917'
|
||||||
|
when channel~'51517' then '51517'
|
||||||
|
when channel~*'4yx' then '4yx'
|
||||||
|
when channel~'好汉' then '好汉'
|
||||||
|
when channel~'51' then '51'
|
||||||
|
when channel~'葫芦侠' then '葫芦侠'
|
||||||
|
when channel~'虫虫' then '虫虫'
|
||||||
|
when channel~'跃游' then '跃游'
|
||||||
|
when channel~'天天' then '天天'
|
||||||
|
when channel~'66' then '66'
|
||||||
|
when channel~'嘉禾' then '嘉禾'
|
||||||
|
when channel~'爱游' then '爱游'
|
||||||
|
when channel~'乐疯玩' then '乐疯玩'
|
||||||
|
when channel~'游戏饭' then '游戏饭'
|
||||||
|
when channel~'百度' then '百度'
|
||||||
|
when channel~'UC' then 'UC'
|
||||||
|
when channel~'网易' then '网易'
|
||||||
|
when channel~'启示科创' then '启示科创'
|
||||||
|
when channel~'抖音' then '抖音'
|
||||||
|
when channel~'搜狗' then '搜狗'
|
||||||
|
when channel~'移端' then '移端'
|
||||||
|
when channel~'千易' then '千易'
|
||||||
|
when channel~'应用市场' then '应用市场'
|
||||||
|
when channel~'360' then '360'
|
||||||
|
when channel~'07073' then '07073'
|
||||||
|
when channel~'巨鳄' then '巨鳄'
|
||||||
|
when channel~'星光斗聚' then '星光斗聚'
|
||||||
|
when channel~'广点通' then '广点通'
|
||||||
|
when channel~'热云' then '热云'
|
||||||
|
when channel~'云刺' then '云刺'
|
||||||
|
when channel~'财泰' then '财泰'
|
||||||
|
when channel~'沈阳阅览' then '沈阳阅览'
|
||||||
|
when channel~'新义' then '新义'
|
||||||
|
when channel~'钰玺公众号' then '钰玺公众号'
|
||||||
|
when channel~'蜀游' then '蜀游'
|
||||||
|
when channel~'月象' then '月象'
|
||||||
|
when channel~'云境' then '云境'
|
||||||
|
when channel~'小米' then '小米'
|
||||||
|
when channel~*'sigmob' then 'Sigmob'
|
||||||
|
when channel~'睿初' then '睿初'
|
||||||
|
when channel~'豌豆荚' then '豌豆荚'
|
||||||
|
when channel~'橙益' then '橙益'
|
||||||
|
when channel~'汉鸣' then '汉鸣'
|
||||||
|
when channel~'因特云' then '因特云'
|
||||||
|
when channel~'奕浪' then '奕浪'
|
||||||
|
when channel~'鸿扬' then '鸿扬'
|
||||||
|
when channel~'新宸睿' then '新宸睿'
|
||||||
|
when channel~'翊宸' then '翊宸'
|
||||||
|
when channel~'巨麦' then '巨麦'
|
||||||
|
when channel~'2345' then '2345'
|
||||||
|
when channel~'烈火封神网页' then '烈火封神网页'
|
||||||
|
when channel~'北星' then '北星'
|
||||||
|
when channel~'承宇齐光' then '承宇齐光'
|
||||||
|
when channel~'微信' then '微信'
|
||||||
|
when channel~'拾元立方' then '拾元立方'
|
||||||
|
when channel~'头条' then '头条'
|
||||||
|
when channel~'洛阳兰奇' then '洛阳兰奇'
|
||||||
|
when channel~'金领' then '金领'
|
||||||
|
when channel~'云游怀旧服' then '云游怀旧服'
|
||||||
|
when channel~'自投' then '自投'
|
||||||
|
when channel~'陕西米效' then '陕西米效'
|
||||||
|
when channel~'芈兔兔' then '芈兔兔'
|
||||||
|
when channel~'辣条山海传' then '辣条山海传'
|
||||||
|
when channel~'钢蹦罗刹海超神器' then '钢蹦罗刹海超神器'
|
||||||
|
when channel~'猫猫上古火龙' then '猫猫上古火龙'
|
||||||
|
when channel~'苍云铭文沉默' then '苍云铭文沉默'
|
||||||
|
when channel~'蓝奏' then '蓝奏'
|
||||||
|
when channel~'三星' then '三星'
|
||||||
|
when channel~'上海堡英' then '上海堡英'
|
||||||
|
when channel~'短信' then '短信'
|
||||||
|
when channel~'朋友圈' then '微信'
|
||||||
|
when channel~'996争霸赛' then '996争霸赛'
|
||||||
|
when channel~'华联' then '华联'
|
||||||
|
when channel~'必应' then '必应'
|
||||||
|
when channel~'野草' then '野草'
|
||||||
|
when channel~'微博' then '微博'
|
||||||
|
when channel~'依目' then '依目'
|
||||||
|
when channel~'腾讯' then '腾讯'
|
||||||
|
when channel~'去玩诸神沉默' then '去玩诸神沉默'
|
||||||
|
when channel~'骏风古龙沉默' then '骏风古龙沉默'
|
||||||
|
when channel~'去玩影月沉默' then '去玩影月沉默'
|
||||||
|
when channel~'丰巢' then '丰巢'
|
||||||
|
when channel~'云想冰雪' then '云想冰雪'
|
||||||
|
when channel~'龙云至尊无限刀' then '龙云至尊无限刀'
|
||||||
|
when channel~'蔚隆私域' then '蔚隆私域'
|
||||||
|
when channel~'云游小极品' then '云游小极品'
|
||||||
|
when channel~'珈蓝沉默' then '珈蓝沉默'
|
||||||
|
when channel~'灵霜传奇' then '灵霜传奇'
|
||||||
|
when channel~*'pp助手' then 'pp助手'
|
||||||
|
when channel~'西瓜沉默超超超变' then '西瓜沉默超超超变'
|
||||||
|
when channel~'白马火龙' then '白马火龙'
|
||||||
|
when channel~'好看' then '好看'
|
||||||
|
when channel~'戎马传奇' then '戎马传奇'
|
||||||
|
when channel~'烛龙相逢沉默' then '烛龙相逢沉默'
|
||||||
|
when channel~'99交易行' then '99交易行'
|
||||||
|
when channel~'洪量' then '洪量'
|
||||||
|
when channel~'小说定制包' then '小说定制包'
|
||||||
|
when channel~'传奇手游' then '传奇手游'
|
||||||
|
when channel~'九天传奇' then '九天传奇'
|
||||||
|
when channel~'猛虎传奇3' then '猛虎传奇3'
|
||||||
|
when channel~'巨灵传奇3' then '巨灵传奇3'
|
||||||
|
when channel~'惊天传奇4' then '惊天传奇4'
|
||||||
|
when channel~'墨府传奇4' then '墨府传奇4'
|
||||||
|
when channel~'盛游火龙' then '盛游火龙'
|
||||||
|
when channel~'中天传奇181' then '中天传奇181'
|
||||||
|
when channel~'中天龙脉大陆' then '中天龙脉大陆'
|
||||||
|
when channel~'潜龙传奇' then '潜龙传奇'
|
||||||
|
when channel~'飞轩火龙' then '飞轩火龙'
|
||||||
|
when channel~'净土沉默复古版' then '净土沉默复古版'
|
||||||
|
when channel~'锋战传奇' then '锋战传奇'
|
||||||
|
when channel~'归龙火龙' then '归龙火龙'
|
||||||
|
when channel~'大楚传奇' then '大楚传奇'
|
||||||
|
when channel~'春秋传奇' then '春秋传奇'
|
||||||
|
when channel~'意意180轻变' then '意意180轻变'
|
||||||
|
when channel~'巨灵传奇4怀旧版' then '巨灵传奇4怀旧版'
|
||||||
|
when channel~'青花传奇' then '青花传奇'
|
||||||
|
when channel~'流失用户回归包' then '流失用户回归包'
|
||||||
|
when channel~'昆山创游' then '昆山创游'
|
||||||
|
when channel~*'ubx' then 'UBX'
|
||||||
|
when channel~'木之无尽沉默' then '木之无尽沉默'
|
||||||
|
when channel~'品动灯火' then '品动灯火'
|
||||||
|
when channel~'宗师传奇' then '宗师传奇'
|
||||||
|
when channel~'小说排名公示' then '小说排名公示'
|
||||||
|
when channel~'北京雨悦美通' then '北京雨悦美通'
|
||||||
|
when channel~*'kook' then 'kook'
|
||||||
|
when channel~'尚聚专属无限刀' then '尚聚专属无限刀'
|
||||||
|
when channel~'优酷' then '优酷'
|
||||||
|
else '其他' end as channel,
|
||||||
|
event_time,user_id,ds::date as new_acc_dt
|
||||||
|
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
|
||||||
|
where acc.ds BETWEEN '${startdate}' AND '${bizdate}'
|
||||||
|
) t
|
||||||
|
) t1
|
||||||
|
where rn=1
|
||||||
|
--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 BETWEEN '${startdate}' AND '${months-1}'
|
||||||
|
group by
|
||||||
|
ds::date,user_id
|
||||||
|
),
|
||||||
|
retention_rd as
|
||||||
|
(
|
||||||
|
select
|
||||||
|
appid,app_name,co_oper_partner,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_ltv_m (index_type,data_month,coop,acc_count,ltv1,ltv7,ltv14,ltv30,ltv60,ltv90,ltv180)
|
||||||
|
|
||||||
|
select
|
||||||
|
'coop_ltv' index_type,
|
||||||
|
TO_CHAR(t1.new_acc_mon, 'YYYY-MM') data_month,
|
||||||
|
t1.co_oper_partner coop,
|
||||||
|
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
|
||||||
|
co_oper_partner,date_trunc('month',new_acc_dt)::date as new_acc_mon,uniq(user_id) as new_user_num
|
||||||
|
from retention_rd
|
||||||
|
where rd=0
|
||||||
|
group by
|
||||||
|
co_oper_partner,date_trunc('month',new_acc_dt)::date
|
||||||
|
) t1
|
||||||
|
left join
|
||||||
|
(
|
||||||
|
select
|
||||||
|
co_oper_partner,
|
||||||
|
date_trunc('month',new_acc_dt)::date as new_acc_mon,
|
||||||
|
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
|
||||||
|
co_oper_partner,date_trunc('month',new_acc_dt)::date
|
||||||
|
) t2 on t1.new_acc_mon=t2.new_acc_mon and t1.co_oper_partner=t2.co_oper_partner
|
||||||
|
;
|
387
996eco/4.sql
Normal file
387
996eco/4.sql
Normal file
@ -0,0 +1,387 @@
|
|||||||
|
-- channel_ltv
|
||||||
|
--------------------
|
||||||
|
-- 可以优化
|
||||||
|
with retention_new_acc as
|
||||||
|
(
|
||||||
|
select
|
||||||
|
appid,app_name,
|
||||||
|
case when account in ('wanxin996', 'qqq492864156','yueyou996') then '玩心'
|
||||||
|
when account in ('13234701199', 'xiongDiwan', 'xiongdi996', '996xiongdi', 'cly225522') then '春秋玩'
|
||||||
|
when account in ('tuantuan6400', 'whtuantuan', 'whzhangyou','whzhangyou1')then'安峰'
|
||||||
|
when account in ('Jinri', 'zhangqian996') then '掌玩'
|
||||||
|
when account in ('zlkj996') then '智灵'
|
||||||
|
when account in ('ssyy1') then '盈优'
|
||||||
|
when account in ('ky6709','wangsiqun') then '恺英'
|
||||||
|
when account in ('hzxs0375','diaobao1') then '勋双'
|
||||||
|
when account in ('nb1290733693', '9377yyeb', '9377syybyy') then '9377'
|
||||||
|
when account in ('longxiang', 'zhanxingbo', '18659080001') then '龙翔'
|
||||||
|
when account in ('13216396033', 'Zwzb2024', 'YP2024') then '玉盘'
|
||||||
|
when account in ('tanwant2', 'tanwan996', 'tw996hz99', 'tw996hz66', 'tanlang996', '15868405282', 'tanwanjx') then '贪玩'
|
||||||
|
when account in ('chongqu001','18968060998') and app_name ~ '【宠趣.*】|【87.*】' then '宠趣'
|
||||||
|
when account in ('youyi888','youyi999') and app_name ~ '【YY.*】|【游奕.*】' then '游奕'
|
||||||
|
when account in ('jinrui','huiqi996','996mailiang','HYXCX','masheng527') then '慧跃'
|
||||||
|
when account in ('biqiwan') then '常州万趣'
|
||||||
|
when account in ('nxn0310') then '成都星楠祥'
|
||||||
|
when account in ('youxinhuyu') then '成都游鑫'
|
||||||
|
when account in ('a9527cc') then '东莞起量'
|
||||||
|
when account in ('yiwan123') then '赣州易玩'
|
||||||
|
when account in ('gzyw6772') then '广州悦玩'
|
||||||
|
when account in ('YL15102760231') then '海南岩岭'
|
||||||
|
when account in ('145929L','hzqy9523') then '杭州乾赟'
|
||||||
|
when account in ('simo123') then '杭州司墨'
|
||||||
|
when account in ('zhaochengzhi') then '杭州速叶'
|
||||||
|
when account in ('masheng527') then '杭州炫灿'
|
||||||
|
when account in ('leijian4') then '湖北瓜玩'
|
||||||
|
when account in ('jiangxicw2025') then '江西超网'
|
||||||
|
when account in ('xc188164') then '江西热血'
|
||||||
|
when account in ('zjzq3585') then '临沂好汉'
|
||||||
|
when account in ('lezhuyou') then '青岛乐猪游'
|
||||||
|
when account in ('quyou') then '厦门趣游'
|
||||||
|
when account in ('jishijiayou') then '上海纪世嘉游'
|
||||||
|
when account in ('mita') then '上海迷塔'
|
||||||
|
when account in ('daimiaohudong') then '四川呆喵'
|
||||||
|
when account in ('whqujie2025') then '武汉趣界云图'
|
||||||
|
when account in ('qfyw2024996') then '武汉全方易维'
|
||||||
|
when account in ('wjyx') then '武汉莴苣'
|
||||||
|
when account in ('yansong') then '徐州木牛游马'
|
||||||
|
when account in ('zjh641391114') then '延边八七互娱'
|
||||||
|
when app_name ~ '【.*?联运' then regexp_replace(app_name, '.*【(.*?)联运.*', '\1')
|
||||||
|
when app_name !~ '【.*?联运' and app_name ~ '.*【(.*?)】.*' then regexp_replace(app_name, '.*【(.*?)】.*', '\1')
|
||||||
|
when channel~'盒子' or channel~'996box' then '盒子'
|
||||||
|
else '其他' end as co_oper_partner,
|
||||||
|
case when channel~'盒子' or channel~'996box' then '盒子'
|
||||||
|
when channel~'ai6' then 'ai6'
|
||||||
|
when channel~'玩心' then '玩心'
|
||||||
|
when channel~'应用宝' then '应用宝'
|
||||||
|
when channel~'纸片' then '纸片'
|
||||||
|
when channel~'团团' then '团团'
|
||||||
|
when channel~'335玩' then '335玩'
|
||||||
|
when channel~'朋克' then '朋克'
|
||||||
|
when channel~'安徽追游' then '安徽追游'
|
||||||
|
when channel~'冰火' then '冰火'
|
||||||
|
when channel~'心乐' then '心乐'
|
||||||
|
when channel ~*'华为|vivo|oppo|魅族|努比亚|联想|酷派|硬核联盟' then '硬核联盟'
|
||||||
|
when channel~'9377' then '9377'
|
||||||
|
when channel~'智灵' then '智灵'
|
||||||
|
when channel~'掌游' then '掌游'
|
||||||
|
when channel~'上士' then '上士'
|
||||||
|
when channel~'攒趣' then '攒趣'
|
||||||
|
when channel~'掌玩' then '掌玩'
|
||||||
|
when channel~'贪玩' then '贪玩'
|
||||||
|
when channel~'wx'or channel~'WX'or channel~'微信' then '微信'
|
||||||
|
when channel~'公众号' then '公众号'
|
||||||
|
when channel~'qq' or channel~'QQ' then 'QQ'
|
||||||
|
--when channel~'quick' then 'quick'
|
||||||
|
when channel~'七牛' then '七牛'
|
||||||
|
when channel~'霸气' then '霸气'
|
||||||
|
when channel~'xy' or channel~'XY' then 'XY'
|
||||||
|
when channel~'芝麻互娱' then '芝麻互娱'
|
||||||
|
when channel~'龙翔' then '龙翔'
|
||||||
|
when channel~'布咕' then '布咕'
|
||||||
|
when channel~'小柠互娱' then '小柠互娱'
|
||||||
|
when channel~'春秋玩' then '春秋玩'
|
||||||
|
when channel~'欢喜时代' then '欢喜时代'
|
||||||
|
when channel~'上游' then '上游'
|
||||||
|
when channel~'倾程' then '倾程'
|
||||||
|
when channel~'绿洲' then '绿洲'
|
||||||
|
when channel~'雷电' then '雷电'
|
||||||
|
when channel~'点点' then '点点'
|
||||||
|
when channel~'小七' then '小七'
|
||||||
|
when channel~'瓜玩' then '瓜玩'
|
||||||
|
when channel~'艺云' then '艺云'
|
||||||
|
when channel~'冠游' then '冠游'
|
||||||
|
when channel~'玄藏' then '玄藏'
|
||||||
|
when channel~'羽龙' then '羽龙'
|
||||||
|
when channel~'星云' then '星云'
|
||||||
|
when channel~'爱尚游' then '爱尚游'
|
||||||
|
when channel~'昊玩' then '昊玩'
|
||||||
|
when channel~'8酷' then '8酷'
|
||||||
|
when channel~'迅玩' then '迅玩'
|
||||||
|
when channel~'星游' then '星游'
|
||||||
|
when channel~'小米' then '小米'
|
||||||
|
when channel~'趣城' then '趣城'
|
||||||
|
when channel~'诺游' then '诺游'
|
||||||
|
when channel~'洛谷' then '洛谷'
|
||||||
|
when channel~'司墨' then '司墨'
|
||||||
|
when channel~'脚印' then '脚印'
|
||||||
|
when channel~'神游' then '神游'
|
||||||
|
when channel~'拓乐' then '拓乐'
|
||||||
|
when channel~'360' then '360'
|
||||||
|
when channel~'日昇' then '日昇'
|
||||||
|
when channel~'触点' then '触点'
|
||||||
|
when channel~'冠游' then '冠游'
|
||||||
|
when channel~'巴兔' then '巴兔'
|
||||||
|
when channel~'天纵' then '天纵'
|
||||||
|
when channel~'早游戏' then '早游戏'
|
||||||
|
when channel~'爱趣' then '爱趣'
|
||||||
|
when channel~'星楠祥' then '星楠祥'
|
||||||
|
when channel~'贪游' then '贪游'
|
||||||
|
when channel~'君游' then '君游'
|
||||||
|
when channel~'996直播间' then '996直播间'
|
||||||
|
when channel~'mumu' then 'mumu'
|
||||||
|
when channel~'吉祥' then '吉祥直播间'
|
||||||
|
when channel~'溪谷' then '溪谷'
|
||||||
|
when channel~'优谷' then '优谷'
|
||||||
|
when channel~'闪趣' then '闪趣'
|
||||||
|
when channel~'8酷' then '8酷'
|
||||||
|
when channel~'抖音' then '抖音'
|
||||||
|
when channel~'斗鱼' then '斗鱼'
|
||||||
|
when channel~'虎牙' then '虎牙'
|
||||||
|
when channel~'巨量' then '巨量'
|
||||||
|
when channel~'快手' then '快手'
|
||||||
|
when channel~'爱奇艺' then '爱奇艺'
|
||||||
|
when channel~'007' then '007'
|
||||||
|
when channel~'圣宏' then '圣宏'
|
||||||
|
when channel~'顺火' then '顺火'
|
||||||
|
when channel~'飞火' then '飞火'
|
||||||
|
when channel~'乐岛' then '乐岛'
|
||||||
|
when channel~'传柒' then '传柒'
|
||||||
|
when channel~'星际' then '星际'
|
||||||
|
when channel~'玖趣' then '玖趣'
|
||||||
|
when channel~*'ku25' then 'ku25'
|
||||||
|
when channel~'8090' then '8090'
|
||||||
|
when channel~*'appstore' then 'AppStore'
|
||||||
|
when channel~'欢娱' then '欢娱'
|
||||||
|
when channel~'逐梦' then '逐梦'
|
||||||
|
when channel~'兴动' then '兴动'
|
||||||
|
when channel~'3733' then '3733'
|
||||||
|
when channel~'第一游戏' then '第一游戏'
|
||||||
|
when channel~'公会' then '公会'
|
||||||
|
when channel~'欢娱' then '欢娱'
|
||||||
|
when channel~'335玩' then '335玩'
|
||||||
|
when channel~*'4yx' then '4yx'
|
||||||
|
when channel~'37' then '37'
|
||||||
|
when channel~'开心' then '开心'
|
||||||
|
when channel~*'ios' or channel~'苹果' then 'ios苹果端具体不详'
|
||||||
|
when channel~'触点' then '触点'
|
||||||
|
when channel~'游码' then '游码'
|
||||||
|
when channel~*'45yx' then '45yx'
|
||||||
|
when channel~'巨量' then '巨量'
|
||||||
|
when channel~'小铃铛' then '小铃铛'
|
||||||
|
when channel~'2345' then '2345'
|
||||||
|
when channel~'梨子' then '梨子'
|
||||||
|
when channel~'麦游' then '麦游'
|
||||||
|
when channel~'群英' then '群英'
|
||||||
|
when channel~'阅文' then '阅文'
|
||||||
|
when channel~*'kopo' then 'kopo'
|
||||||
|
when channel~'创启' then '创启'
|
||||||
|
when channel~'4366' then '4366'
|
||||||
|
when channel~'大楚' then '大楚'
|
||||||
|
when channel~'巅峰' then '巅峰'
|
||||||
|
when channel~'277' then '277'
|
||||||
|
when channel~'112233' then '112233'
|
||||||
|
when channel~'714' then '714'
|
||||||
|
when channel~'4399' then '4399'
|
||||||
|
when channel~'追忆' then '追忆'
|
||||||
|
when channel~*'yy' then 'yy'
|
||||||
|
when channel~'588' then '588'
|
||||||
|
when channel~'八门' then '八门'
|
||||||
|
when channel~*'pdd' then 'pdd'
|
||||||
|
when channel~'9917' then '9917'
|
||||||
|
when channel~'51517' then '51517'
|
||||||
|
when channel~*'4yx' then '4yx'
|
||||||
|
when channel~'好汉' then '好汉'
|
||||||
|
when channel~'51' then '51'
|
||||||
|
when channel~'葫芦侠' then '葫芦侠'
|
||||||
|
when channel~'虫虫' then '虫虫'
|
||||||
|
when channel~'跃游' then '跃游'
|
||||||
|
when channel~'天天' then '天天'
|
||||||
|
when channel~'66' then '66'
|
||||||
|
when channel~'嘉禾' then '嘉禾'
|
||||||
|
when channel~'爱游' then '爱游'
|
||||||
|
when channel~'乐疯玩' then '乐疯玩'
|
||||||
|
when channel~'游戏饭' then '游戏饭'
|
||||||
|
when channel~'百度' then '百度'
|
||||||
|
when channel~'UC' then 'UC'
|
||||||
|
when channel~'网易' then '网易'
|
||||||
|
when channel~'启示科创' then '启示科创'
|
||||||
|
when channel~'抖音' then '抖音'
|
||||||
|
when channel~'搜狗' then '搜狗'
|
||||||
|
when channel~'移端' then '移端'
|
||||||
|
when channel~'千易' then '千易'
|
||||||
|
when channel~'应用市场' then '应用市场'
|
||||||
|
when channel~'360' then '360'
|
||||||
|
when channel~'07073' then '07073'
|
||||||
|
when channel~'巨鳄' then '巨鳄'
|
||||||
|
when channel~'星光斗聚' then '星光斗聚'
|
||||||
|
when channel~'广点通' then '广点通'
|
||||||
|
when channel~'热云' then '热云'
|
||||||
|
when channel~'云刺' then '云刺'
|
||||||
|
when channel~'财泰' then '财泰'
|
||||||
|
when channel~'沈阳阅览' then '沈阳阅览'
|
||||||
|
when channel~'新义' then '新义'
|
||||||
|
when channel~'钰玺公众号' then '钰玺公众号'
|
||||||
|
when channel~'蜀游' then '蜀游'
|
||||||
|
when channel~'月象' then '月象'
|
||||||
|
when channel~'云境' then '云境'
|
||||||
|
when channel~'小米' then '小米'
|
||||||
|
when channel~*'sigmob' then 'Sigmob'
|
||||||
|
when channel~'睿初' then '睿初'
|
||||||
|
when channel~'豌豆荚' then '豌豆荚'
|
||||||
|
when channel~'橙益' then '橙益'
|
||||||
|
when channel~'汉鸣' then '汉鸣'
|
||||||
|
when channel~'因特云' then '因特云'
|
||||||
|
when channel~'奕浪' then '奕浪'
|
||||||
|
when channel~'鸿扬' then '鸿扬'
|
||||||
|
when channel~'新宸睿' then '新宸睿'
|
||||||
|
when channel~'翊宸' then '翊宸'
|
||||||
|
when channel~'巨麦' then '巨麦'
|
||||||
|
when channel~'2345' then '2345'
|
||||||
|
when channel~'烈火封神网页' then '烈火封神网页'
|
||||||
|
when channel~'北星' then '北星'
|
||||||
|
when channel~'承宇齐光' then '承宇齐光'
|
||||||
|
when channel~'微信' then '微信'
|
||||||
|
when channel~'拾元立方' then '拾元立方'
|
||||||
|
when channel~'头条' then '头条'
|
||||||
|
when channel~'洛阳兰奇' then '洛阳兰奇'
|
||||||
|
when channel~'金领' then '金领'
|
||||||
|
when channel~'云游怀旧服' then '云游怀旧服'
|
||||||
|
when channel~'自投' then '自投'
|
||||||
|
when channel~'陕西米效' then '陕西米效'
|
||||||
|
when channel~'芈兔兔' then '芈兔兔'
|
||||||
|
when channel~'辣条山海传' then '辣条山海传'
|
||||||
|
when channel~'钢蹦罗刹海超神器' then '钢蹦罗刹海超神器'
|
||||||
|
when channel~'猫猫上古火龙' then '猫猫上古火龙'
|
||||||
|
when channel~'苍云铭文沉默' then '苍云铭文沉默'
|
||||||
|
when channel~'蓝奏' then '蓝奏'
|
||||||
|
when channel~'三星' then '三星'
|
||||||
|
when channel~'上海堡英' then '上海堡英'
|
||||||
|
when channel~'短信' then '短信'
|
||||||
|
when channel~'朋友圈' then '微信'
|
||||||
|
when channel~'996争霸赛' then '996争霸赛'
|
||||||
|
when channel~'华联' then '华联'
|
||||||
|
when channel~'必应' then '必应'
|
||||||
|
when channel~'野草' then '野草'
|
||||||
|
when channel~'微博' then '微博'
|
||||||
|
when channel~'依目' then '依目'
|
||||||
|
when channel~'腾讯' then '腾讯'
|
||||||
|
when channel~'去玩诸神沉默' then '去玩诸神沉默'
|
||||||
|
when channel~'骏风古龙沉默' then '骏风古龙沉默'
|
||||||
|
when channel~'去玩影月沉默' then '去玩影月沉默'
|
||||||
|
when channel~'丰巢' then '丰巢'
|
||||||
|
when channel~'云想冰雪' then '云想冰雪'
|
||||||
|
when channel~'龙云至尊无限刀' then '龙云至尊无限刀'
|
||||||
|
when channel~'蔚隆私域' then '蔚隆私域'
|
||||||
|
when channel~'云游小极品' then '云游小极品'
|
||||||
|
when channel~'珈蓝沉默' then '珈蓝沉默'
|
||||||
|
when channel~'灵霜传奇' then '灵霜传奇'
|
||||||
|
when channel~*'pp助手' then 'pp助手'
|
||||||
|
when channel~'西瓜沉默超超超变' then '西瓜沉默超超超变'
|
||||||
|
when channel~'白马火龙' then '白马火龙'
|
||||||
|
when channel~'好看' then '好看'
|
||||||
|
when channel~'戎马传奇' then '戎马传奇'
|
||||||
|
when channel~'烛龙相逢沉默' then '烛龙相逢沉默'
|
||||||
|
when channel~'99交易行' then '99交易行'
|
||||||
|
when channel~'洪量' then '洪量'
|
||||||
|
when channel~'小说定制包' then '小说定制包'
|
||||||
|
when channel~'传奇手游' then '传奇手游'
|
||||||
|
when channel~'九天传奇' then '九天传奇'
|
||||||
|
when channel~'猛虎传奇3' then '猛虎传奇3'
|
||||||
|
when channel~'巨灵传奇3' then '巨灵传奇3'
|
||||||
|
when channel~'惊天传奇4' then '惊天传奇4'
|
||||||
|
when channel~'墨府传奇4' then '墨府传奇4'
|
||||||
|
when channel~'盛游火龙' then '盛游火龙'
|
||||||
|
when channel~'中天传奇181' then '中天传奇181'
|
||||||
|
when channel~'中天龙脉大陆' then '中天龙脉大陆'
|
||||||
|
when channel~'潜龙传奇' then '潜龙传奇'
|
||||||
|
when channel~'飞轩火龙' then '飞轩火龙'
|
||||||
|
when channel~'净土沉默复古版' then '净土沉默复古版'
|
||||||
|
when channel~'锋战传奇' then '锋战传奇'
|
||||||
|
when channel~'归龙火龙' then '归龙火龙'
|
||||||
|
when channel~'大楚传奇' then '大楚传奇'
|
||||||
|
when channel~'春秋传奇' then '春秋传奇'
|
||||||
|
when channel~'意意180轻变' then '意意180轻变'
|
||||||
|
when channel~'巨灵传奇4怀旧版' then '巨灵传奇4怀旧版'
|
||||||
|
when channel~'青花传奇' then '青花传奇'
|
||||||
|
when channel~'流失用户回归包' then '流失用户回归包'
|
||||||
|
when channel~'昆山创游' then '昆山创游'
|
||||||
|
when channel~*'ubx' then 'UBX'
|
||||||
|
when channel~'木之无尽沉默' then '木之无尽沉默'
|
||||||
|
when channel~'品动灯火' then '品动灯火'
|
||||||
|
when channel~'宗师传奇' then '宗师传奇'
|
||||||
|
when channel~'小说排名公示' then '小说排名公示'
|
||||||
|
when channel~'北京雨悦美通' then '北京雨悦美通'
|
||||||
|
when channel~*'kook' then 'kook'
|
||||||
|
when channel~'尚聚专属无限刀' then '尚聚专属无限刀'
|
||||||
|
when channel~'优酷' then '优酷'
|
||||||
|
else '其他' end as channel,
|
||||||
|
event_time,user_id,ds::date as new_acc_dt
|
||||||
|
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
|
||||||
|
where rn=1
|
||||||
|
and ds BETWEEN '${startdate}' AND '${bizdate}'
|
||||||
|
),
|
||||||
|
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 BETWEEN '${startdate}' AND '${bizdate}'
|
||||||
|
group by
|
||||||
|
ds::date,user_id
|
||||||
|
),
|
||||||
|
retention_rd as
|
||||||
|
(
|
||||||
|
select
|
||||||
|
appid,app_name,co_oper_partner,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_ltv_m (index_type,data_month,channel,acc_count,ltv1,ltv7,ltv14,ltv30,ltv60,ltv90,ltv180)
|
||||||
|
select
|
||||||
|
'channel_ltv' index_type,TO_CHAR(t1.new_acc_mon, 'YYYY-MM') data_month,t1.channel,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
|
||||||
|
channel,date_trunc('month',new_acc_dt)::date as new_acc_mon,uniq(user_id) as new_user_num
|
||||||
|
from retention_rd
|
||||||
|
where rd=0
|
||||||
|
group by
|
||||||
|
channel,date_trunc('month',new_acc_dt)::date
|
||||||
|
) t1
|
||||||
|
left join
|
||||||
|
(
|
||||||
|
select
|
||||||
|
channel,date_trunc('month',new_acc_dt)::date as new_acc_mon,
|
||||||
|
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
|
||||||
|
channel,date_trunc('month',new_acc_dt)::date
|
||||||
|
) t2 on t1.new_acc_mon=t2.new_acc_mon and t1.channel=t2.channel
|
||||||
|
;
|
||||||
|
|
||||||
|
|
193
996eco/5.sql
Normal file
193
996eco/5.sql
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
-- avg_tag_ltv
|
||||||
|
|
||||||
|
WITH ga AS (
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
bind_game_id
|
||||||
|
FROM public.gm_apply
|
||||||
|
WHERE bind_type = 1 AND bind_game_type = 1
|
||||||
|
),
|
||||||
|
tg AS (
|
||||||
|
SELECT
|
||||||
|
game_id,
|
||||||
|
string_agg(DISTINCT CASE WHEN tag in ('神器','复古','沉默','火龙','合击','迷失','小极品','大极品','二合一','铭文','冰雪','宠物','战神','暗黑','元素','忘忧','BUFF','天罡') THEN tag ELSE NULL END,',') AS play_tag,
|
||||||
|
string_agg(DISTINCT CASE WHEN tag in ('1.70','1.76','1.80','1.85','1.95')THEN tag ELSE NULL END, ',') AS ver_tag,
|
||||||
|
string_agg(DISTINCT CASE WHEN tag in ('经典','微变','中变','超变') THEN tag ELSE NULL END,',') AS value_tag,
|
||||||
|
string_agg(DISTINCT CASE WHEN tag in ('单职业','三职业','多职业') THEN tag ELSE NULL END,',') AS job_tag,
|
||||||
|
string_agg(DISTINCT CASE WHEN tag in ('3D','开服1年','开服2年','开服3年','开服4年') THEN tag ELSE NULL END,',') AS feature_tag
|
||||||
|
FROM public.game_tags
|
||||||
|
GROUP BY game_id
|
||||||
|
),
|
||||||
|
po AS (
|
||||||
|
SELECT
|
||||||
|
appid,
|
||||||
|
ds,
|
||||||
|
user_id,
|
||||||
|
SUM(amount) / 100 AS pay_amount
|
||||||
|
FROM public.ods_payment_order
|
||||||
|
WHERE status = 1
|
||||||
|
AND ds BETWEEN '${startdate}' AND '${bizdate}'
|
||||||
|
GROUP BY appid, ds, user_id
|
||||||
|
),
|
||||||
|
na AS (
|
||||||
|
SELECT
|
||||||
|
ds,
|
||||||
|
appid,
|
||||||
|
user_id
|
||||||
|
FROM public.ods_newly_account
|
||||||
|
WHERE 1=1
|
||||||
|
AND ds BETWEEN '${startdate}' AND '${bizdate}'
|
||||||
|
),
|
||||||
|
|
||||||
|
base_data AS (SELECT
|
||||||
|
na.ds::date AS cohort_date,
|
||||||
|
na.appid,
|
||||||
|
ga.name AS appname,
|
||||||
|
tg.play_tag,
|
||||||
|
tg.ver_tag,
|
||||||
|
tg.value_tag,
|
||||||
|
tg.job_tag,
|
||||||
|
tg.feature_tag,
|
||||||
|
na.user_id,
|
||||||
|
po.pay_amount,
|
||||||
|
po.ds::date - na.ds::date AS n_day
|
||||||
|
FROM na
|
||||||
|
INNER JOIN
|
||||||
|
ga ON na.appid = ga.id
|
||||||
|
LEFT JOIN
|
||||||
|
po ON na.appid = po.appid AND na.user_id = po.user_id AND po.ds::date BETWEEN na.ds::date AND na.ds::date + 120
|
||||||
|
LEFT JOIN
|
||||||
|
tg ON ga.bind_game_id = tg.game_id),
|
||||||
|
ltv_base AS (
|
||||||
|
SELECT
|
||||||
|
TO_CHAR(DATE_TRUNC('month', cohort_date), 'YYYY-MM') AS data_month,
|
||||||
|
appid,
|
||||||
|
play_tag,
|
||||||
|
-- appname,
|
||||||
|
UNIQ(user_id) AS new_cnt,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 0 AND n_day <= 0 THEN pay_amount ELSE NULL END) AS amount0,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 1 AND n_day <= 1 THEN pay_amount ELSE NULL END) AS amount1,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 2 AND n_day <= 2 THEN pay_amount ELSE NULL END) AS amount2,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 3 AND n_day <= 3 THEN pay_amount ELSE NULL END) AS amount3,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 4 AND n_day <= 4 THEN pay_amount ELSE NULL END) AS amount4,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 5 AND n_day <= 5 THEN pay_amount ELSE NULL END) AS amount5,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 6 AND n_day <= 6 THEN pay_amount ELSE NULL END) AS amount6,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 7 AND n_day <= 7 THEN pay_amount ELSE NULL END) AS amount7,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 8 AND n_day <= 8 THEN pay_amount ELSE NULL END) AS amount8,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 9 AND n_day <= 9 THEN pay_amount ELSE NULL END) AS amount9,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 10 AND n_day <= 10 THEN pay_amount ELSE NULL END) AS amount10,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 11 AND n_day <= 11 THEN pay_amount ELSE NULL END) AS amount11,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 12 AND n_day <= 12 THEN pay_amount ELSE NULL END) AS amount12,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 13 AND n_day <= 13 THEN pay_amount ELSE NULL END) AS amount13,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 14 AND n_day <= 14 THEN pay_amount ELSE NULL END) AS amount14,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 15 AND n_day <= 15 THEN pay_amount ELSE NULL END) AS amount15,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 16 AND n_day <= 16 THEN pay_amount ELSE NULL END) AS amount16,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 17 AND n_day <= 17 THEN pay_amount ELSE NULL END) AS amount17,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 18 AND n_day <= 18 THEN pay_amount ELSE NULL END) AS amount18,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 19 AND n_day <= 19 THEN pay_amount ELSE NULL END) AS amount19,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 20 AND n_day <= 20 THEN pay_amount ELSE NULL END) AS amount20,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 21 AND n_day <= 21 THEN pay_amount ELSE NULL END) AS amount21,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 22 AND n_day <= 22 THEN pay_amount ELSE NULL END) AS amount22,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 23 AND n_day <= 23 THEN pay_amount ELSE NULL END) AS amount23,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 24 AND n_day <= 24 THEN pay_amount ELSE NULL END) AS amount24,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 25 AND n_day <= 25 THEN pay_amount ELSE NULL END) AS amount25,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 26 AND n_day <= 26 THEN pay_amount ELSE NULL END) AS amount26,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 27 AND n_day <= 27 THEN pay_amount ELSE NULL END) AS amount27,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 28 AND n_day <= 28 THEN pay_amount ELSE NULL END) AS amount28,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 29 AND n_day <= 29 THEN pay_amount ELSE NULL END) AS amount29,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 30 AND n_day <= 30 THEN pay_amount ELSE NULL END) AS amount30,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 31 AND n_day <= 31 THEN pay_amount ELSE NULL END) AS amount31,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 45 AND n_day <= 45 THEN pay_amount ELSE NULL END) AS amount45,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 60 AND n_day <= 60 THEN pay_amount ELSE NULL END) AS amount60,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 90 AND n_day <= 90 THEN pay_amount ELSE NULL END) AS amount90,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 120 AND n_day <= 120 THEN pay_amount ELSE NULL END) AS amount120,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 0 AND n_day <= 0 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV0,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 1 AND n_day <= 1 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV1,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 2 AND n_day <= 2 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV2,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 3 AND n_day <= 3 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV3,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 4 AND n_day <= 4 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV4,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 5 AND n_day <= 5 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV5,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 6 AND n_day <= 6 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV6,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 7 AND n_day <= 7 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV7,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 8 AND n_day <= 8 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV8,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 9 AND n_day <= 9 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV9,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 10 AND n_day <= 10 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV10,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 11 AND n_day <= 11 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV11,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 12 AND n_day <= 12 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV12,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 13 AND n_day <= 13 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV13,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 14 AND n_day <= 14 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV14,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 15 AND n_day <= 15 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV15,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 16 AND n_day <= 16 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV16,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 17 AND n_day <= 17 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV17,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 18 AND n_day <= 18 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV18,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 19 AND n_day <= 19 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV19,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 20 AND n_day <= 20 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV20,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 21 AND n_day <= 21 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV21,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 22 AND n_day <= 22 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV22,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 23 AND n_day <= 23 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV23,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 24 AND n_day <= 24 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV24,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 25 AND n_day <= 25 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV25,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 26 AND n_day <= 26 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV26,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 27 AND n_day <= 27 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV27,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 28 AND n_day <= 28 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV28,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 29 AND n_day <= 29 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV29,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 30 AND n_day <= 30 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV30,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 31 AND n_day <= 31 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV31,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 45 AND n_day <= 45 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV45,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 60 AND n_day <= 60 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV60,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 90 AND n_day <= 90 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV90,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 120 AND n_day <= 120 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV120
|
||||||
|
|
||||||
|
FROM base_data
|
||||||
|
WHERE play_tag IS NOT NULL
|
||||||
|
GROUP BY GROUPING SETS((data_month, appid, play_tag), (appid, play_tag)))
|
||||||
|
|
||||||
|
|
||||||
|
INSERT INTO
|
||||||
|
datasci.ads_996eco_index_ltv_m (index_type,data_month,play_tag,acc_count,ltv0,ltv1,ltv2,ltv3,ltv4,ltv5,ltv6,ltv7,ltv8,ltv9,ltv10,ltv11,ltv12,ltv13,ltv14,ltv15,ltv16,ltv17,ltv18,ltv19,ltv20,ltv21,ltv22,ltv23,ltv24,ltv25,ltv26,ltv27,ltv28,ltv29,ltv30,ltv31,ltv45,ltv60,ltv90,ltv120)
|
||||||
|
SELECT
|
||||||
|
'avg_tag_ltv' index_type,
|
||||||
|
data_month,
|
||||||
|
play_tag,
|
||||||
|
AVG(new_cnt) AS acc_count,
|
||||||
|
AVG(ltv0) AS ltv0,
|
||||||
|
AVG(ltv1) AS ltv1,
|
||||||
|
AVG(ltv2) AS ltv2,
|
||||||
|
AVG(ltv3) AS ltv3,
|
||||||
|
AVG(ltv4) AS ltv4,
|
||||||
|
AVG(ltv5) AS ltv5,
|
||||||
|
AVG(ltv6) AS ltv6,
|
||||||
|
AVG(ltv7) AS ltv7,
|
||||||
|
AVG(ltv8) AS ltv8,
|
||||||
|
AVG(ltv9) AS ltv9,
|
||||||
|
AVG(ltv10) AS ltv10,
|
||||||
|
AVG(ltv11) AS ltv11,
|
||||||
|
AVG(ltv12) AS ltv12,
|
||||||
|
AVG(ltv13) AS ltv13,
|
||||||
|
AVG(ltv14) AS ltv14,
|
||||||
|
AVG(ltv15) AS ltv15,
|
||||||
|
AVG(ltv16) AS ltv16,
|
||||||
|
AVG(ltv17) AS ltv17,
|
||||||
|
AVG(ltv18) AS ltv18,
|
||||||
|
AVG(ltv19) AS ltv19,
|
||||||
|
AVG(ltv20) AS ltv20,
|
||||||
|
AVG(ltv21) AS ltv21,
|
||||||
|
AVG(ltv22) AS ltv22,
|
||||||
|
AVG(ltv23) AS ltv23,
|
||||||
|
AVG(ltv24) AS ltv24,
|
||||||
|
AVG(ltv25) AS ltv25,
|
||||||
|
AVG(ltv26) AS ltv26,
|
||||||
|
AVG(ltv27) AS ltv27,
|
||||||
|
AVG(ltv28) AS ltv28,
|
||||||
|
AVG(ltv29) AS ltv29,
|
||||||
|
AVG(ltv30) AS ltv30,
|
||||||
|
AVG(ltv31) AS ltv31,
|
||||||
|
AVG(ltv45) AS ltv45,
|
||||||
|
AVG(ltv60) AS ltv60,
|
||||||
|
AVG(ltv90) AS ltv90,
|
||||||
|
AVG(ltv120) AS ltv120
|
||||||
|
FROM ltv_base
|
||||||
|
WHERE new_cnt > 100
|
||||||
|
GROUP BY 1, 2, 3;
|
||||||
|
|
164
996eco/6.sql
Normal file
164
996eco/6.sql
Normal file
@ -0,0 +1,164 @@
|
|||||||
|
-- play_tag_ltv play_tag_amount_ltv
|
||||||
|
|
||||||
|
WITH ga AS (
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
bind_game_id
|
||||||
|
FROM public.gm_apply
|
||||||
|
WHERE bind_type = 1 AND bind_game_type = 1
|
||||||
|
),
|
||||||
|
tg AS (
|
||||||
|
SELECT
|
||||||
|
game_id,
|
||||||
|
string_agg(DISTINCT CASE WHEN tag in ('神器','复古','沉默','火龙','合击','迷失','小极品','大极品','二合一','铭文','冰雪','宠物','战神','暗黑','元素','忘忧','BUFF','天罡') THEN tag ELSE NULL END,',') AS play_tag,
|
||||||
|
string_agg(DISTINCT CASE WHEN tag in ('1.70','1.76','1.80','1.85','1.95')THEN tag ELSE NULL END, ',') AS ver_tag,
|
||||||
|
string_agg(DISTINCT CASE WHEN tag in ('经典','微变','中变','超变') THEN tag ELSE NULL END,',') AS value_tag,
|
||||||
|
string_agg(DISTINCT CASE WHEN tag in ('单职业','三职业','多职业') THEN tag ELSE NULL END,',') AS job_tag,
|
||||||
|
string_agg(DISTINCT CASE WHEN tag in ('3D','开服1年','开服2年','开服3年','开服4年') THEN tag ELSE NULL END,',') AS feature_tag
|
||||||
|
FROM public.game_tags
|
||||||
|
GROUP BY game_id
|
||||||
|
),
|
||||||
|
po AS (
|
||||||
|
SELECT
|
||||||
|
appid,
|
||||||
|
ds,
|
||||||
|
user_id,
|
||||||
|
SUM(amount) / 100 AS pay_amount
|
||||||
|
FROM public.ods_payment_order
|
||||||
|
WHERE status = 1
|
||||||
|
AND ds::date BETWEEN '${startdate}' AND '${bizdate}'
|
||||||
|
GROUP BY appid, ds, user_id
|
||||||
|
),
|
||||||
|
na AS (
|
||||||
|
SELECT
|
||||||
|
ds,
|
||||||
|
appid,
|
||||||
|
user_id
|
||||||
|
FROM public.ods_newly_account
|
||||||
|
WHERE 1=1
|
||||||
|
AND ds::date BETWEEN '${startdate}' AND '${bizdate}'
|
||||||
|
),
|
||||||
|
|
||||||
|
base_data AS (SELECT
|
||||||
|
na.ds::date AS cohort_date,
|
||||||
|
na.appid,
|
||||||
|
ga.name AS appname,
|
||||||
|
tg.play_tag,
|
||||||
|
tg.ver_tag,
|
||||||
|
tg.value_tag,
|
||||||
|
tg.job_tag,
|
||||||
|
tg.feature_tag,
|
||||||
|
na.user_id,
|
||||||
|
po.pay_amount,
|
||||||
|
po.ds::date - na.ds::date AS n_day
|
||||||
|
FROM na
|
||||||
|
INNER JOIN
|
||||||
|
ga ON na.appid = ga.id
|
||||||
|
LEFT JOIN
|
||||||
|
po ON na.appid = po.appid AND na.user_id = po.user_id AND po.ds::date BETWEEN na.ds::date AND na.ds::date + 120
|
||||||
|
LEFT JOIN
|
||||||
|
tg ON ga.bind_game_id = tg.game_id)
|
||||||
|
INSERT INTO
|
||||||
|
datasci.ads_996eco_index_ltv_m (index_type,data_month,play_tag,acc_count,ltv0,ltv1,ltv2,ltv3,ltv4,ltv5,ltv6,ltv7,ltv8,ltv9,ltv10,ltv11,ltv12,ltv13,ltv14,ltv15,ltv16,ltv17,ltv18,ltv19,ltv20,ltv21,ltv22,ltv23,ltv24,ltv25,ltv26,ltv27,ltv28,ltv29,ltv30,ltv31,ltv45,ltv60,ltv90,ltv120)
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
'play_tag_amount_ltv' index_type,
|
||||||
|
TO_CHAR(DATE_TRUNC('month', cohort_date), 'YYYY-MM') AS data_month,
|
||||||
|
appid,
|
||||||
|
play_tag,
|
||||||
|
-- appname,
|
||||||
|
UNIQ(user_id) AS new_cnt,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 0 AND n_day <= 0 THEN pay_amount ELSE NULL END) AS ltv0,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 1 AND n_day <= 1 THEN pay_amount ELSE NULL END) AS ltv1,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 2 AND n_day <= 2 THEN pay_amount ELSE NULL END) AS ltv2,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 3 AND n_day <= 3 THEN pay_amount ELSE NULL END) AS ltv3,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 4 AND n_day <= 4 THEN pay_amount ELSE NULL END) AS ltv4,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 5 AND n_day <= 5 THEN pay_amount ELSE NULL END) AS ltv5,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 6 AND n_day <= 6 THEN pay_amount ELSE NULL END) AS ltv6,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 7 AND n_day <= 7 THEN pay_amount ELSE NULL END) AS ltv7,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 8 AND n_day <= 8 THEN pay_amount ELSE NULL END) AS ltv8,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 9 AND n_day <= 9 THEN pay_amount ELSE NULL END) AS ltv9,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 10 AND n_day <= 10 THEN pay_amount ELSE NULL END) AS ltv10,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 11 AND n_day <= 11 THEN pay_amount ELSE NULL END) AS ltv11,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 12 AND n_day <= 12 THEN pay_amount ELSE NULL END) AS ltv12,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 13 AND n_day <= 13 THEN pay_amount ELSE NULL END) AS ltv13,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 14 AND n_day <= 14 THEN pay_amount ELSE NULL END) AS ltv14,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 15 AND n_day <= 15 THEN pay_amount ELSE NULL END) AS ltv15,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 16 AND n_day <= 16 THEN pay_amount ELSE NULL END) AS ltv16,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 17 AND n_day <= 17 THEN pay_amount ELSE NULL END) AS ltv17,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 18 AND n_day <= 18 THEN pay_amount ELSE NULL END) AS ltv18,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 19 AND n_day <= 19 THEN pay_amount ELSE NULL END) AS ltv19,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 20 AND n_day <= 20 THEN pay_amount ELSE NULL END) AS ltv20,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 21 AND n_day <= 21 THEN pay_amount ELSE NULL END) AS ltv21,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 22 AND n_day <= 22 THEN pay_amount ELSE NULL END) AS ltv22,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 23 AND n_day <= 23 THEN pay_amount ELSE NULL END) AS ltv23,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 24 AND n_day <= 24 THEN pay_amount ELSE NULL END) AS ltv24,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 25 AND n_day <= 25 THEN pay_amount ELSE NULL END) AS ltv25,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 26 AND n_day <= 26 THEN pay_amount ELSE NULL END) AS ltv26,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 27 AND n_day <= 27 THEN pay_amount ELSE NULL END) AS ltv27,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 28 AND n_day <= 28 THEN pay_amount ELSE NULL END) AS ltv28,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 29 AND n_day <= 29 THEN pay_amount ELSE NULL END) AS ltv29,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 30 AND n_day <= 30 THEN pay_amount ELSE NULL END) AS ltv30,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 31 AND n_day <= 31 THEN pay_amount ELSE NULL END) AS ltv31,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 45 AND n_day <= 45 THEN pay_amount ELSE NULL END) AS ltv45,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 60 AND n_day <= 60 THEN pay_amount ELSE NULL END) AS ltv60,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 90 AND n_day <= 90 THEN pay_amount ELSE NULL END) AS ltv90,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 120 AND n_day <= 120 THEN pay_amount ELSE NULL END) AS ltv120
|
||||||
|
|
||||||
|
|
||||||
|
FROM base_data
|
||||||
|
WHERE play_tag IS NOT NULL
|
||||||
|
GROUP BY GROUPING SETS((data_month, appid, play_tag), (appid, play_tag))
|
||||||
|
UNION ALL
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
'play_tag_ltv' index_type,
|
||||||
|
TO_CHAR(DATE_TRUNC('month', cohort_date), 'YYYY-MM') AS data_month,
|
||||||
|
appid,
|
||||||
|
play_tag,
|
||||||
|
-- appname,
|
||||||
|
UNIQ(user_id) AS new_cnt,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 0 AND n_day <= 0 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv0,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 1 AND n_day <= 1 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv1,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 2 AND n_day <= 2 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv2,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 3 AND n_day <= 3 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv3,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 4 AND n_day <= 4 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv4,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 5 AND n_day <= 5 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv5,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 6 AND n_day <= 6 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv6,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 7 AND n_day <= 7 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv7,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 8 AND n_day <= 8 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv8,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 9 AND n_day <= 9 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv9,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 10 AND n_day <= 10 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv10,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 11 AND n_day <= 11 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv11,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 12 AND n_day <= 12 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv12,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 13 AND n_day <= 13 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv13,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 14 AND n_day <= 14 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv14,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 15 AND n_day <= 15 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv15,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 16 AND n_day <= 16 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv16,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 17 AND n_day <= 17 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv17,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 18 AND n_day <= 18 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv18,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 19 AND n_day <= 19 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv19,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 20 AND n_day <= 20 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv20,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 21 AND n_day <= 21 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv21,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 22 AND n_day <= 22 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv22,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 23 AND n_day <= 23 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv23,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 24 AND n_day <= 24 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv24,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 25 AND n_day <= 25 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv25,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 26 AND n_day <= 26 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv26,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 27 AND n_day <= 27 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv27,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 28 AND n_day <= 28 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv28,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 29 AND n_day <= 29 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv29,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 30 AND n_day <= 30 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv30,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 31 AND n_day <= 31 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv31,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 45 AND n_day <= 45 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv45,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 60 AND n_day <= 60 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv60,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 90 AND n_day <= 90 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv90,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 120 AND n_day <= 120 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv120
|
||||||
|
|
||||||
|
|
||||||
|
FROM base_data
|
||||||
|
WHERE play_tag IS NOT NULL
|
||||||
|
GROUP BY GROUPING SETS((data_month, appid, play_tag), (appid, play_tag))
|
||||||
|
;
|
||||||
|
|
102
996eco/7.sql
Normal file
102
996eco/7.sql
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
-- tg_ltv
|
||||||
|
|
||||||
|
with retention_new_acc as
|
||||||
|
(
|
||||||
|
select
|
||||||
|
appid,app_name,channel,bind_game_id,
|
||||||
|
event_time,user_id,ds::date as new_acc_dt
|
||||||
|
from
|
||||||
|
(
|
||||||
|
select
|
||||||
|
bind_game_id,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,channel,event_time,user_id,ds,gm.bind_game_id
|
||||||
|
from public.ods_newly_account acc
|
||||||
|
inner join
|
||||||
|
(
|
||||||
|
select id,name,bind_game_id
|
||||||
|
from public.gm_apply
|
||||||
|
where bind_game_type=1
|
||||||
|
) gm on acc.appid=gm.id
|
||||||
|
) t
|
||||||
|
) t1
|
||||||
|
where rn=1
|
||||||
|
and ds BETWEEN '${startdate}' 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 BETWEEN '${startdate}' AND '${bizdate}'
|
||||||
|
group by
|
||||||
|
ds::date,user_id
|
||||||
|
),
|
||||||
|
retention_rd as
|
||||||
|
(
|
||||||
|
select
|
||||||
|
appid,app_name,channel,tg_play.tag as tg_play,tg_ver.tag as tg_ver,tg_value.tag as tg_value,tg_job.tag as tg_job,tg_feature.tag as tg_feature,
|
||||||
|
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 outer join
|
||||||
|
(select game_id,tag from public.game_tags where tag in ('神器','复古','沉默','火龙','合击','迷失','小极品','大极品','二合一','铭文','冰雪','宠物','战神','暗黑','元素','忘忧','BUFF','天罡'))tg_play
|
||||||
|
on t1.bind_game_id=tg_play.game_id
|
||||||
|
left outer join
|
||||||
|
(select game_id,tag from public.game_tags where tag in ('1.70','1.76','1.80','1.85','1.95'))tg_ver
|
||||||
|
on t1.bind_game_id=tg_ver.game_id
|
||||||
|
left outer join
|
||||||
|
(select game_id,tag from public.game_tags where tag in ('经典','微变','中变','超变'))tg_value
|
||||||
|
on t1.bind_game_id=tg_value.game_id
|
||||||
|
left outer join
|
||||||
|
(select game_id,tag from public.game_tags where tag in ('单职业','三职业','多职业'))tg_job
|
||||||
|
on t1.bind_game_id=tg_job.game_id
|
||||||
|
left outer join
|
||||||
|
(select game_id,tag from public.game_tags where tag in ('3D','开服1年','开服2年','开服3年','开服4年'))tg_feature
|
||||||
|
on t1.bind_game_id=tg_feature.game_id
|
||||||
|
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_ltv_m (index_type,tg_play,tg_ver,tg_value,tg_job,tg_feature,data_month,new_user_num,ltv1,ltv7,ltv14,ltv30,ltv60,ltv90,ltv180)
|
||||||
|
|
||||||
|
select 'tg_ltv' index_type,
|
||||||
|
t1.tg_play,t1.tg_ver,t1.tg_value,t1.tg_job,t1.tg_feature,TO_CHAR(t1.new_acc_mon, 'YYYY-MM') data_month,t1.new_user_num,t2.ret_1 ltv1,ret_7 ltv7,ret_14 ltv14,ret_30 ltv30,ret_60 ltv60,ret_90 ltv90,ret_180 ltv180
|
||||||
|
from
|
||||||
|
(
|
||||||
|
select
|
||||||
|
coalesce(tg_play,'未知') as tg_play,coalesce(tg_ver,'未知') as tg_ver,coalesce(tg_value,'未知') as tg_value,coalesce(tg_job,'未知') as tg_job,coalesce(tg_feature,'未知') as tg_feature,
|
||||||
|
date_trunc('month',new_acc_dt) as new_acc_mon,uniq(user_id) as new_user_num
|
||||||
|
from retention_rd
|
||||||
|
where rd=0
|
||||||
|
group by
|
||||||
|
coalesce(tg_play,'未知') ,coalesce(tg_ver,'未知') ,coalesce(tg_value,'未知') ,coalesce(tg_job,'未知') ,coalesce(tg_feature,'未知'),date_trunc('month',new_acc_dt)
|
||||||
|
) t1
|
||||||
|
left join
|
||||||
|
(
|
||||||
|
select
|
||||||
|
coalesce(tg_play,'未知') as tg_play,coalesce(tg_ver,'未知') as tg_ver,coalesce(tg_value,'未知') as tg_value,coalesce(tg_job,'未知') as tg_job,
|
||||||
|
coalesce(tg_feature,'未知') as tg_feature,date_trunc('month',new_acc_dt) as new_acc_mon,
|
||||||
|
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
|
||||||
|
coalesce(tg_play,'未知') ,coalesce(tg_ver,'未知') ,coalesce(tg_value,'未知') ,coalesce(tg_job,'未知') ,coalesce(tg_feature,'未知'),date_trunc('month',new_acc_dt)
|
||||||
|
) t2 on t1.new_acc_mon=t2.new_acc_mon and t1.tg_play=t2.tg_play and t1.tg_ver=t2.tg_ver and t1.tg_value=t2.tg_value and t1.tg_job=t2.tg_job and t1.tg_feature=t2.tg_feature
|
||||||
|
;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
--bizdate 20250431 bizmonth 20250401 bizmonth
|
--bizdate 20250430 hisdate 20240801
|
||||||
|
|
||||||
CREATE TABLE datasci.ads_996eco_index_ltv_d (
|
CREATE TABLE datasci.ads_996eco_index_ltv_d (
|
||||||
index_type text,
|
index_type text,
|
||||||
|
@ -1,111 +1,11 @@
|
|||||||
DELETE FROM datasci.ads_996eco_index_ltv_m WHERE 1=1;
|
truncate table datasci.ads_996eco_index_ltv_m ;
|
||||||
|
|
||||||
-- 从24年1月到现在 数据量无法做增量
|
-------------------- avg
|
||||||
-------------------- 1
|
|
||||||
--LTV
|
|
||||||
WITH ga AS (
|
|
||||||
SELECT
|
|
||||||
id,
|
|
||||||
name,
|
|
||||||
bind_game_id
|
|
||||||
FROM public.gm_apply
|
|
||||||
WHERE bind_type = 1 AND bind_game_type = 1
|
|
||||||
),
|
|
||||||
|
|
||||||
po AS (
|
|
||||||
SELECT
|
|
||||||
appid,
|
|
||||||
ds,
|
|
||||||
user_id,
|
|
||||||
|
|
||||||
SUM(amount) / 100 AS pay_amount
|
|
||||||
FROM public.ods_payment_order
|
|
||||||
WHERE status = 1
|
|
||||||
AND ds::date BETWEEN '2024-10-01' AND CURRENT_DATE - INTERVAL'1day'
|
|
||||||
GROUP BY appid, ds, user_id
|
|
||||||
),
|
|
||||||
na AS (
|
|
||||||
SELECT
|
|
||||||
ds,
|
|
||||||
appid,
|
|
||||||
case when device_type ~*'h5' then 'H5'
|
|
||||||
when device_type ~*'pc' then 'PC'
|
|
||||||
when device_type ~*'ios' then 'IOS'
|
|
||||||
when device_type ~*'mac' then 'mac'
|
|
||||||
when device_type ~*'android' then 'Android'
|
|
||||||
when device_type ~*'harmony' then '鸿蒙'
|
|
||||||
else '其他' end AS re_device_type,
|
|
||||||
user_id
|
|
||||||
FROM public.ods_newly_account
|
|
||||||
WHERE 1=1
|
|
||||||
AND ds::date BETWEEN '2024-10-01' AND '2025-03-31'
|
|
||||||
),
|
|
||||||
|
|
||||||
base_data AS (SELECT
|
|
||||||
na.ds::date AS cohort_date,
|
|
||||||
na.appid,
|
|
||||||
ga.name AS appname,
|
|
||||||
na.re_device_type,
|
|
||||||
na.user_id,
|
|
||||||
po.pay_amount,
|
|
||||||
po.ds::date - na.ds::date AS n_day
|
|
||||||
FROM na
|
|
||||||
INNER JOIN
|
|
||||||
ga ON na.appid = ga.id
|
|
||||||
LEFT JOIN
|
|
||||||
po ON na.appid = po.appid AND na.user_id = po.user_id AND po.ds::date BETWEEN na.ds::date AND na.ds::date + 120
|
|
||||||
)
|
|
||||||
|
|
||||||
SELECT
|
|
||||||
're_device_ltv' index_type,
|
|
||||||
re_device_type,
|
|
||||||
appid,
|
|
||||||
UNIQ(user_id) AS acc_count,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 0 AND n_day <= 0 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV0,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 1 AND n_day <= 1 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV1,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 2 AND n_day <= 2 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV2,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 3 AND n_day <= 3 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV3,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 4 AND n_day <= 4 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV4,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 5 AND n_day <= 5 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV5,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 6 AND n_day <= 6 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV6,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 7 AND n_day <= 7 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV7,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 8 AND n_day <= 8 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV8,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 9 AND n_day <= 9 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV9,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 10 AND n_day <= 10 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV10,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 11 AND n_day <= 11 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV11,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 12 AND n_day <= 12 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV12,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 13 AND n_day <= 13 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV13,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 14 AND n_day <= 14 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV14,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 15 AND n_day <= 15 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV15,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 16 AND n_day <= 16 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV16,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 17 AND n_day <= 17 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV17,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 18 AND n_day <= 18 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV18,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 19 AND n_day <= 19 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV19,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 20 AND n_day <= 20 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV20,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 21 AND n_day <= 21 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV21,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 22 AND n_day <= 22 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV22,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 23 AND n_day <= 23 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV23,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 24 AND n_day <= 24 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV24,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 25 AND n_day <= 25 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV25,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 26 AND n_day <= 26 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV26,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 27 AND n_day <= 27 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV27,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 28 AND n_day <= 28 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV28,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 29 AND n_day <= 29 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV29,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 30 AND n_day <= 30 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV30,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 31 AND n_day <= 31 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV31,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 45 AND n_day <= 45 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV45,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 60 AND n_day <= 60 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV60,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 90 AND n_day <= 90 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV90,
|
|
||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 120 AND n_day <= 120 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV120
|
|
||||||
FROM base_data
|
|
||||||
-- WHERE play_tag IS NOT NULL
|
|
||||||
GROUP BY appid, re_device_type
|
|
||||||
;
|
|
||||||
|
|
||||||
--------------------
|
|
||||||
-- 从24年1月到现在 数据量无法做增量
|
-- 从24年1月到现在 数据量无法做增量
|
||||||
|
|
||||||
|
SET hg_computing_resource = 'serverless';
|
||||||
|
|
||||||
|
SET hg_experimental_serverless_computing_max_cores = 64;
|
||||||
|
|
||||||
WITH ga AS ( -- 筛选传奇类产品的appid
|
WITH ga AS ( -- 筛选传奇类产品的appid
|
||||||
SELECT
|
SELECT
|
||||||
@ -129,7 +29,7 @@ po AS ( -- 付费基础表
|
|||||||
SUM(amount) / 100 AS pay_amount
|
SUM(amount) / 100 AS pay_amount
|
||||||
FROM public.ods_payment_order
|
FROM public.ods_payment_order
|
||||||
WHERE status = 1
|
WHERE status = 1
|
||||||
AND ds::date BETWEEN '2024-01-01' AND CURRENT_DATE - INTERVAL'1DAY'
|
AND ds BETWEEN '${startdate}' AND '${bizdate}'
|
||||||
GROUP BY appid, ds, user_id
|
GROUP BY appid, ds, user_id
|
||||||
),
|
),
|
||||||
na AS ( -- 新增基础表
|
na AS ( -- 新增基础表
|
||||||
@ -139,7 +39,7 @@ na AS ( -- 新增基础表
|
|||||||
user_id
|
user_id
|
||||||
FROM public.ods_newly_account
|
FROM public.ods_newly_account
|
||||||
WHERE 1=1
|
WHERE 1=1
|
||||||
AND ds::date BETWEEN '2024-01-01' AND CURRENT_DATE - INTERVAL'1DAY'
|
AND ds::date BETWEEN '${startdate}' AND '${bizdate}'
|
||||||
)
|
)
|
||||||
,
|
,
|
||||||
base_data AS ( -- 联合计算新增人数和后续付费及间隔天数
|
base_data AS ( -- 联合计算新增人数和后续付费及间隔天数
|
||||||
@ -219,9 +119,10 @@ SELECT
|
|||||||
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 120 AND n_day <= 120 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv120
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 120 AND n_day <= 120 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS ltv120
|
||||||
FROM base_data
|
FROM base_data
|
||||||
GROUP BY 1, 2, 3)
|
GROUP BY 1, 2, 3)
|
||||||
|
INSERT INTO
|
||||||
|
datasci.ads_996eco_index_ltv_m (index_type,data_month,is_box,avg_new,ltv0,ltv1,ltv2,ltv3,ltv4,ltv5,ltv6,ltv7,ltv8,ltv9,ltv10,ltv11,ltv12,ltv13,ltv14,ltv15,ltv16,ltv17,ltv18,ltv19,ltv20,ltv21,ltv22,ltv23,ltv24,ltv25,ltv26,ltv27,ltv28,ltv29,ltv30,ltv31,ltv45,ltv60,ltv90,ltv120)
|
||||||
SELECT
|
SELECT
|
||||||
'avg_ltv' index_type,
|
'avg' index_type,
|
||||||
data_month,
|
data_month,
|
||||||
is_box,
|
is_box,
|
||||||
AVG(acc_count) AS avg_new, -- 基于要求,取每个appid的平均值
|
AVG(acc_count) AS avg_new, -- 基于要求,取每个appid的平均值
|
||||||
@ -265,7 +166,117 @@ FROM ltv_base
|
|||||||
WHERE acc_count > 100 -- 此处是随便拍的一个避免新增人数过少导致LTV受影响较大的阈值,可根据实际情况调整(从600改成了100)
|
WHERE acc_count > 100 -- 此处是随便拍的一个避免新增人数过少导致LTV受影响较大的阈值,可根据实际情况调整(从600改成了100)
|
||||||
GROUP BY 1, 2, 3;
|
GROUP BY 1, 2, 3;
|
||||||
|
|
||||||
--------------------
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- 从24年1月到现在 数据量无法做增量
|
||||||
|
-------------------- 1
|
||||||
|
--re_device_ltv
|
||||||
|
WITH ga AS (
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
bind_game_id
|
||||||
|
FROM public.gm_apply
|
||||||
|
WHERE bind_type = 1 AND bind_game_type = 1
|
||||||
|
),
|
||||||
|
|
||||||
|
po AS (
|
||||||
|
SELECT
|
||||||
|
appid,
|
||||||
|
ds,
|
||||||
|
user_id,
|
||||||
|
SUM(amount) / 100 AS pay_amount
|
||||||
|
FROM public.ods_payment_order
|
||||||
|
WHERE status = 1
|
||||||
|
AND ds BETWEEN '${startdate}' AND '${bizdate}'
|
||||||
|
GROUP BY appid, ds, user_id
|
||||||
|
),
|
||||||
|
na AS (
|
||||||
|
SELECT
|
||||||
|
ds,
|
||||||
|
appid,
|
||||||
|
case when device_type ~*'h5' then 'H5'
|
||||||
|
when device_type ~*'pc' then 'PC'
|
||||||
|
when device_type ~*'ios' then 'IOS'
|
||||||
|
when device_type ~*'mac' then 'mac'
|
||||||
|
when device_type ~*'android' then 'Android'
|
||||||
|
when device_type ~*'harmony' then '鸿蒙'
|
||||||
|
else '其他' end AS re_device_type,
|
||||||
|
user_id
|
||||||
|
FROM public.ods_newly_account
|
||||||
|
WHERE 1=1
|
||||||
|
AND ds BETWEEN '${startdate}' AND '${bizdate}'
|
||||||
|
),
|
||||||
|
|
||||||
|
base_data AS (SELECT
|
||||||
|
na.ds::date AS cohort_date,
|
||||||
|
na.appid,
|
||||||
|
ga.name AS appname,
|
||||||
|
na.re_device_type,
|
||||||
|
na.user_id,
|
||||||
|
po.pay_amount,
|
||||||
|
po.ds::date - na.ds::date AS n_day
|
||||||
|
FROM na
|
||||||
|
INNER JOIN
|
||||||
|
ga ON na.appid = ga.id
|
||||||
|
LEFT JOIN
|
||||||
|
po ON na.appid = po.appid AND na.user_id = po.user_id AND po.ds::date BETWEEN na.ds::date AND na.ds::date + 120
|
||||||
|
)
|
||||||
|
INSERT INTO
|
||||||
|
datasci.ads_996eco_index_ltv_m (index_type,re_device_type,appid,acc_count,ltv0,ltv1,ltv2,ltv3,ltv4,ltv5,ltv6,ltv7,ltv8,ltv9,ltv10,ltv11,ltv12,ltv13,ltv14,ltv15,ltv16,ltv17,ltv18,ltv19,ltv20,ltv21,ltv22,ltv23,ltv24,ltv25,ltv26,ltv27,ltv28,ltv29,ltv30,ltv31,ltv45,ltv60,ltv90,ltv120)
|
||||||
|
SELECT
|
||||||
|
're_device_ltv' index_type,
|
||||||
|
re_device_type,
|
||||||
|
appid,
|
||||||
|
UNIQ(user_id) AS acc_count,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 0 AND n_day <= 0 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV0,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 1 AND n_day <= 1 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV1,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 2 AND n_day <= 2 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV2,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 3 AND n_day <= 3 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV3,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 4 AND n_day <= 4 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV4,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 5 AND n_day <= 5 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV5,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 6 AND n_day <= 6 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV6,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 7 AND n_day <= 7 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV7,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 8 AND n_day <= 8 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV8,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 9 AND n_day <= 9 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV9,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 10 AND n_day <= 10 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV10,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 11 AND n_day <= 11 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV11,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 12 AND n_day <= 12 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV12,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 13 AND n_day <= 13 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV13,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 14 AND n_day <= 14 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV14,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 15 AND n_day <= 15 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV15,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 16 AND n_day <= 16 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV16,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 17 AND n_day <= 17 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV17,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 18 AND n_day <= 18 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV18,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 19 AND n_day <= 19 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV19,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 20 AND n_day <= 20 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV20,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 21 AND n_day <= 21 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV21,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 22 AND n_day <= 22 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV22,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 23 AND n_day <= 23 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV23,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 24 AND n_day <= 24 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV24,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 25 AND n_day <= 25 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV25,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 26 AND n_day <= 26 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV26,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 27 AND n_day <= 27 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV27,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 28 AND n_day <= 28 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV28,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 29 AND n_day <= 29 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV29,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 30 AND n_day <= 30 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV30,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 31 AND n_day <= 31 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV31,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 45 AND n_day <= 45 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV45,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 60 AND n_day <= 60 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV60,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 90 AND n_day <= 90 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV90,
|
||||||
|
SUM(CASE WHEN CURRENT_DATE - cohort_date - 1 >= 120 AND n_day <= 120 THEN pay_amount ELSE NULL END)::numeric / UNIQ(user_id)::numeric AS LTV120
|
||||||
|
FROM base_data
|
||||||
|
GROUP BY appid, re_device_type
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- coop_ltv
|
||||||
|
-------------------- pending
|
||||||
-- 可以优化
|
-- 可以优化
|
||||||
with retention_new_acc as
|
with retention_new_acc as
|
||||||
(
|
(
|
||||||
@ -563,10 +574,10 @@ with retention_new_acc as
|
|||||||
left join public.dim_gm_info b on a.account=b.account
|
left join public.dim_gm_info b on a.account=b.account
|
||||||
where bind_game_type=1
|
where bind_game_type=1
|
||||||
) gm on acc.appid=gm.id
|
) gm on acc.appid=gm.id
|
||||||
|
where acc.ds BETWEEN '${startdate}' AND '${bizdate}'
|
||||||
) t
|
) t
|
||||||
) t1
|
) t1
|
||||||
where rn=1
|
where rn=1
|
||||||
and ds between '${hisdate}' and '${bizdate}'
|
|
||||||
--and user_id='1419067566'
|
--and user_id='1419067566'
|
||||||
),
|
),
|
||||||
retention_active_detail as
|
retention_active_detail as
|
||||||
@ -580,7 +591,7 @@ retention_active_detail as
|
|||||||
from public.gm_apply
|
from public.gm_apply
|
||||||
where bind_game_type=1
|
where bind_game_type=1
|
||||||
) t2 on t1.appid=t2.id
|
) t2 on t1.appid=t2.id
|
||||||
where t1.ds>='${hisdate}' and t1.ds<=to_char(dateadd('${bizdate}'::date,31,'dd'),'yyyymmdd')
|
where t1.ds BETWEEN '${startdate}' AND '${months-1}'
|
||||||
group by
|
group by
|
||||||
ds::date,user_id
|
ds::date,user_id
|
||||||
),
|
),
|
||||||
@ -595,6 +606,9 @@ retention_rd as
|
|||||||
--t1.user_id='1419067566'
|
--t1.user_id='1419067566'
|
||||||
)
|
)
|
||||||
----联运商留存
|
----联运商留存
|
||||||
|
INSERT INTO
|
||||||
|
datasci.ads_996eco_index_ltv_m (index_type,data_month,coop,acc_count,ltv1,ltv7,ltv14,ltv30,ltv60,ltv90,ltv180)
|
||||||
|
|
||||||
select
|
select
|
||||||
'coop_ltv' index_type,
|
'coop_ltv' index_type,
|
||||||
TO_CHAR(t1.new_acc_mon, 'YYYY-MM') data_month,
|
TO_CHAR(t1.new_acc_mon, 'YYYY-MM') data_month,
|
||||||
@ -635,6 +649,8 @@ left join
|
|||||||
) t2 on t1.new_acc_mon=t2.new_acc_mon and t1.co_oper_partner=t2.co_oper_partner
|
) t2 on t1.new_acc_mon=t2.new_acc_mon and t1.co_oper_partner=t2.co_oper_partner
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
|
-- channel_ltv
|
||||||
--------------------
|
--------------------
|
||||||
-- 可以优化
|
-- 可以优化
|
||||||
with retention_new_acc as
|
with retention_new_acc as
|
||||||
@ -961,8 +977,7 @@ with retention_new_acc as
|
|||||||
) t
|
) t
|
||||||
) t1
|
) t1
|
||||||
where rn=1
|
where rn=1
|
||||||
and ds between '${hisdate}' and '${bizdate}'
|
and ds BETWEEN '${startdate}' AND '${bizdate}'
|
||||||
--and user_id='1419067566'
|
|
||||||
),
|
),
|
||||||
retention_active_detail as
|
retention_active_detail as
|
||||||
(
|
(
|
||||||
@ -975,7 +990,7 @@ retention_active_detail as
|
|||||||
from public.gm_apply
|
from public.gm_apply
|
||||||
where bind_game_type=1
|
where bind_game_type=1
|
||||||
) t2 on t1.appid=t2.id
|
) t2 on t1.appid=t2.id
|
||||||
where t1.ds>='${hisdate}' and t1.ds<=to_char(dateadd('${bizdate}'::date,31,'dd'),'yyyymmdd')
|
where t1.ds BETWEEN '${startdate}' AND '${bizdate}'
|
||||||
group by
|
group by
|
||||||
ds::date,user_id
|
ds::date,user_id
|
||||||
),
|
),
|
||||||
@ -990,6 +1005,8 @@ retention_rd as
|
|||||||
--t1.user_id='1419067566'
|
--t1.user_id='1419067566'
|
||||||
)
|
)
|
||||||
--渠道留存
|
--渠道留存
|
||||||
|
INSERT INTO
|
||||||
|
datasci.ads_996eco_index_ltv_m (index_type,data_month,channel,acc_count,ltv1,ltv7,ltv14,ltv30,ltv60,ltv90,ltv180)
|
||||||
select
|
select
|
||||||
'channel_ltv' index_type,TO_CHAR(t1.new_acc_mon, 'YYYY-MM') data_month,t1.channel,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
|
'channel_ltv' index_type,TO_CHAR(t1.new_acc_mon, 'YYYY-MM') data_month,t1.channel,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
|
from
|
||||||
@ -1019,109 +1036,8 @@ left join
|
|||||||
) t2 on t1.new_acc_mon=t2.new_acc_mon and t1.channel=t2.channel
|
) t2 on t1.new_acc_mon=t2.new_acc_mon and t1.channel=t2.channel
|
||||||
;
|
;
|
||||||
|
|
||||||
--------------------
|
|
||||||
-- 从24年10月到现在 数据量无法做增量
|
|
||||||
|
|
||||||
with retention_new_acc as
|
|
||||||
(
|
|
||||||
select
|
|
||||||
appid,app_name,channel,bind_game_id,
|
|
||||||
event_time,user_id,ds::date as new_acc_dt
|
|
||||||
from
|
|
||||||
(
|
|
||||||
select
|
|
||||||
bind_game_id,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,channel,event_time,user_id,ds,gm.bind_game_id
|
|
||||||
from public.ods_newly_account acc
|
|
||||||
inner join
|
|
||||||
(
|
|
||||||
select id,name,bind_game_id
|
|
||||||
from public.gm_apply
|
|
||||||
where bind_game_type=1
|
|
||||||
) gm on acc.appid=gm.id
|
|
||||||
) t
|
|
||||||
) t1
|
|
||||||
where rn=1
|
|
||||||
and 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
|
|
||||||
appid,app_name,channel,tg_play.tag as tg_play,tg_ver.tag as tg_ver,tg_value.tag as tg_value,tg_job.tag as tg_job,tg_feature.tag as tg_feature,
|
|
||||||
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 outer join
|
|
||||||
(select game_id,tag from public.game_tags where tag in ('神器','复古','沉默','火龙','合击','迷失','小极品','大极品','二合一','铭文','冰雪','宠物','战神','暗黑','元素','忘忧','BUFF','天罡'))tg_play
|
|
||||||
on t1.bind_game_id=tg_play.game_id
|
|
||||||
left outer join
|
|
||||||
(select game_id,tag from public.game_tags where tag in ('1.70','1.76','1.80','1.85','1.95'))tg_ver
|
|
||||||
on t1.bind_game_id=tg_ver.game_id
|
|
||||||
left outer join
|
|
||||||
(select game_id,tag from public.game_tags where tag in ('经典','微变','中变','超变'))tg_value
|
|
||||||
on t1.bind_game_id=tg_value.game_id
|
|
||||||
left outer join
|
|
||||||
(select game_id,tag from public.game_tags where tag in ('单职业','三职业','多职业'))tg_job
|
|
||||||
on t1.bind_game_id=tg_job.game_id
|
|
||||||
left outer join
|
|
||||||
(select game_id,tag from public.game_tags where tag in ('3D','开服1年','开服2年','开服3年','开服4年'))tg_feature
|
|
||||||
on t1.bind_game_id=tg_feature.game_id
|
|
||||||
where t2.dt-t1.new_acc_dt in (0,1,7,14,30,60,90,180)
|
|
||||||
--t1.user_id='1419067566'
|
|
||||||
)
|
|
||||||
|
|
||||||
select
|
|
||||||
'channel_ltv' index_type,TO_CHAR(t1.new_acc_mon, 'YYYY-MM') data_month ,t1.tg_play,t1.tg_ver,t1.tg_value,t1.tg_job,t1.tg_feature,t1.new_user_num,
|
|
||||||
t2.ret_1 ltv1,ret_7 ltv7,ret_14 ltv14,ret_30 ltv30,ret_60 ltv60,ret_90 ltv90,ret_180 ltv180
|
|
||||||
from
|
|
||||||
(
|
|
||||||
select
|
|
||||||
coalesce(tg_play,'未知') as tg_play,coalesce(tg_ver,'未知') as tg_ver,coalesce(tg_value,'未知') as tg_value,coalesce(tg_job,'未知') as tg_job,coalesce(tg_feature,'未知') as tg_feature,
|
|
||||||
date_trunc('month',new_acc_dt) as new_acc_mon,uniq(user_id) as new_user_num
|
|
||||||
from retention_rd
|
|
||||||
where rd=0
|
|
||||||
group by
|
|
||||||
coalesce(tg_play,'未知') ,coalesce(tg_ver,'未知') ,coalesce(tg_value,'未知') ,coalesce(tg_job,'未知') ,coalesce(tg_feature,'未知'),date_trunc('month',new_acc_dt)
|
|
||||||
) t1
|
|
||||||
left join
|
|
||||||
(
|
|
||||||
select
|
|
||||||
coalesce(tg_play,'未知') as tg_play,coalesce(tg_ver,'未知') as tg_ver,coalesce(tg_value,'未知') as tg_value,coalesce(tg_job,'未知') as tg_job,
|
|
||||||
coalesce(tg_feature,'未知') as tg_feature,date_trunc('month',new_acc_dt) as new_acc_mon,
|
|
||||||
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
|
|
||||||
coalesce(tg_play,'未知') ,coalesce(tg_ver,'未知') ,coalesce(tg_value,'未知') ,coalesce(tg_job,'未知') ,coalesce(tg_feature,'未知'),date_trunc('month',new_acc_dt)
|
|
||||||
) t2 on t1.new_acc_mon=t2.new_acc_mon and t1.tg_play=t2.tg_play and t1.tg_ver=t2.tg_ver and t1.tg_value=t2.tg_value and t1.tg_job=t2.tg_job and t1.tg_feature=t2.tg_feature
|
|
||||||
limit 10000
|
|
||||||
;
|
|
||||||
|
|
||||||
|
-- avg_tag_ltv
|
||||||
|
|
||||||
WITH ga AS (
|
WITH ga AS (
|
||||||
SELECT
|
SELECT
|
||||||
@ -1150,7 +1066,7 @@ po AS (
|
|||||||
SUM(amount) / 100 AS pay_amount
|
SUM(amount) / 100 AS pay_amount
|
||||||
FROM public.ods_payment_order
|
FROM public.ods_payment_order
|
||||||
WHERE status = 1
|
WHERE status = 1
|
||||||
AND ds::date BETWEEN '2024-10-01' AND current_date - interval'1day'
|
AND ds BETWEEN '${startdate}' AND '${bizdate}'
|
||||||
GROUP BY appid, ds, user_id
|
GROUP BY appid, ds, user_id
|
||||||
),
|
),
|
||||||
na AS (
|
na AS (
|
||||||
@ -1160,7 +1076,7 @@ na AS (
|
|||||||
user_id
|
user_id
|
||||||
FROM public.ods_newly_account
|
FROM public.ods_newly_account
|
||||||
WHERE 1=1
|
WHERE 1=1
|
||||||
AND ds::date BETWEEN '2024-10-01' AND '2025-03-31'
|
AND ds BETWEEN '${startdate}' AND '${bizdate}'
|
||||||
),
|
),
|
||||||
|
|
||||||
base_data AS (SELECT
|
base_data AS (SELECT
|
||||||
@ -1266,8 +1182,11 @@ FROM base_data
|
|||||||
WHERE play_tag IS NOT NULL
|
WHERE play_tag IS NOT NULL
|
||||||
GROUP BY GROUPING SETS((data_month, appid, play_tag), (appid, play_tag)))
|
GROUP BY GROUPING SETS((data_month, appid, play_tag), (appid, play_tag)))
|
||||||
|
|
||||||
|
|
||||||
|
INSERT INTO
|
||||||
|
datasci.ads_996eco_index_ltv_m (index_type,data_month,play_tag,acc_count,ltv0,ltv1,ltv2,ltv3,ltv4,ltv5,ltv6,ltv7,ltv8,ltv9,ltv10,ltv11,ltv12,ltv13,ltv14,ltv15,ltv16,ltv17,ltv18,ltv19,ltv20,ltv21,ltv22,ltv23,ltv24,ltv25,ltv26,ltv27,ltv28,ltv29,ltv30,ltv31,ltv45,ltv60,ltv90,ltv120)
|
||||||
SELECT
|
SELECT
|
||||||
'play_tag_ltv' index_type,
|
'avg_tag_ltv' index_type,
|
||||||
data_month,
|
data_month,
|
||||||
play_tag,
|
play_tag,
|
||||||
AVG(new_cnt) AS acc_count,
|
AVG(new_cnt) AS acc_count,
|
||||||
@ -1312,6 +1231,9 @@ WHERE new_cnt > 100
|
|||||||
GROUP BY 1, 2, 3;
|
GROUP BY 1, 2, 3;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- play_tag_ltv play_tag_amount_ltv
|
||||||
|
|
||||||
WITH ga AS (
|
WITH ga AS (
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
id,
|
||||||
@ -1339,7 +1261,7 @@ po AS (
|
|||||||
SUM(amount) / 100 AS pay_amount
|
SUM(amount) / 100 AS pay_amount
|
||||||
FROM public.ods_payment_order
|
FROM public.ods_payment_order
|
||||||
WHERE status = 1
|
WHERE status = 1
|
||||||
AND ds::date BETWEEN '2024-10-01' AND current_date - interval'1day'
|
AND ds::date BETWEEN '${startdate}' AND '${bizdate}'
|
||||||
GROUP BY appid, ds, user_id
|
GROUP BY appid, ds, user_id
|
||||||
),
|
),
|
||||||
na AS (
|
na AS (
|
||||||
@ -1349,7 +1271,7 @@ na AS (
|
|||||||
user_id
|
user_id
|
||||||
FROM public.ods_newly_account
|
FROM public.ods_newly_account
|
||||||
WHERE 1=1
|
WHERE 1=1
|
||||||
AND ds::date BETWEEN '2024-10-01' AND '2025-03-31'
|
AND ds::date BETWEEN '${startdate}' AND '${bizdate}'
|
||||||
),
|
),
|
||||||
|
|
||||||
base_data AS (SELECT
|
base_data AS (SELECT
|
||||||
@ -1371,6 +1293,8 @@ base_data AS (SELECT
|
|||||||
po ON na.appid = po.appid AND na.user_id = po.user_id AND po.ds::date BETWEEN na.ds::date AND na.ds::date + 120
|
po ON na.appid = po.appid AND na.user_id = po.user_id AND po.ds::date BETWEEN na.ds::date AND na.ds::date + 120
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
tg ON ga.bind_game_id = tg.game_id)
|
tg ON ga.bind_game_id = tg.game_id)
|
||||||
|
INSERT INTO
|
||||||
|
datasci.ads_996eco_index_ltv_m (index_type,data_month,play_tag,acc_count,ltv0,ltv1,ltv2,ltv3,ltv4,ltv5,ltv6,ltv7,ltv8,ltv9,ltv10,ltv11,ltv12,ltv13,ltv14,ltv15,ltv16,ltv17,ltv18,ltv19,ltv20,ltv21,ltv22,ltv23,ltv24,ltv25,ltv26,ltv27,ltv28,ltv29,ltv30,ltv31,ltv45,ltv60,ltv90,ltv120)
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
'play_tag_amount_ltv' index_type,
|
'play_tag_amount_ltv' index_type,
|
||||||
@ -1470,4 +1394,109 @@ SELECT
|
|||||||
FROM base_data
|
FROM base_data
|
||||||
WHERE play_tag IS NOT NULL
|
WHERE play_tag IS NOT NULL
|
||||||
GROUP BY GROUPING SETS((data_month, appid, play_tag), (appid, play_tag))
|
GROUP BY GROUPING SETS((data_month, appid, play_tag), (appid, play_tag))
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- tg_ltv
|
||||||
|
|
||||||
|
with retention_new_acc as
|
||||||
|
(
|
||||||
|
select
|
||||||
|
appid,app_name,channel,bind_game_id,
|
||||||
|
event_time,user_id,ds::date as new_acc_dt
|
||||||
|
from
|
||||||
|
(
|
||||||
|
select
|
||||||
|
bind_game_id,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,channel,event_time,user_id,ds,gm.bind_game_id
|
||||||
|
from public.ods_newly_account acc
|
||||||
|
inner join
|
||||||
|
(
|
||||||
|
select id,name,bind_game_id
|
||||||
|
from public.gm_apply
|
||||||
|
where bind_game_type=1
|
||||||
|
) gm on acc.appid=gm.id
|
||||||
|
) t
|
||||||
|
) t1
|
||||||
|
where rn=1
|
||||||
|
and ds BETWEEN '${startdate}' 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 BETWEEN '${startdate}' AND '${bizdate}'
|
||||||
|
group by
|
||||||
|
ds::date,user_id
|
||||||
|
),
|
||||||
|
retention_rd as
|
||||||
|
(
|
||||||
|
select
|
||||||
|
appid,app_name,channel,tg_play.tag as tg_play,tg_ver.tag as tg_ver,tg_value.tag as tg_value,tg_job.tag as tg_job,tg_feature.tag as tg_feature,
|
||||||
|
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 outer join
|
||||||
|
(select game_id,tag from public.game_tags where tag in ('神器','复古','沉默','火龙','合击','迷失','小极品','大极品','二合一','铭文','冰雪','宠物','战神','暗黑','元素','忘忧','BUFF','天罡'))tg_play
|
||||||
|
on t1.bind_game_id=tg_play.game_id
|
||||||
|
left outer join
|
||||||
|
(select game_id,tag from public.game_tags where tag in ('1.70','1.76','1.80','1.85','1.95'))tg_ver
|
||||||
|
on t1.bind_game_id=tg_ver.game_id
|
||||||
|
left outer join
|
||||||
|
(select game_id,tag from public.game_tags where tag in ('经典','微变','中变','超变'))tg_value
|
||||||
|
on t1.bind_game_id=tg_value.game_id
|
||||||
|
left outer join
|
||||||
|
(select game_id,tag from public.game_tags where tag in ('单职业','三职业','多职业'))tg_job
|
||||||
|
on t1.bind_game_id=tg_job.game_id
|
||||||
|
left outer join
|
||||||
|
(select game_id,tag from public.game_tags where tag in ('3D','开服1年','开服2年','开服3年','开服4年'))tg_feature
|
||||||
|
on t1.bind_game_id=tg_feature.game_id
|
||||||
|
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_ltv_m (index_type,tg_play,tg_ver,tg_value,tg_job,tg_feature,data_month,acc_count,ltv1,ltv7,ltv14,ltv30,ltv60,ltv90,ltv180)
|
||||||
|
|
||||||
|
select 'tg_ltv' index_type,
|
||||||
|
t1.tg_play,t1.tg_ver,t1.tg_value,t1.tg_job,t1.tg_feature,TO_CHAR(t1.new_acc_mon, 'YYYY-MM') data_month,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
|
||||||
|
coalesce(tg_play,'未知') as tg_play,coalesce(tg_ver,'未知') as tg_ver,coalesce(tg_value,'未知') as tg_value,coalesce(tg_job,'未知') as tg_job,coalesce(tg_feature,'未知') as tg_feature,
|
||||||
|
date_trunc('month',new_acc_dt) as new_acc_mon,uniq(user_id) as new_user_num
|
||||||
|
from retention_rd
|
||||||
|
where rd=0
|
||||||
|
group by
|
||||||
|
coalesce(tg_play,'未知') ,coalesce(tg_ver,'未知') ,coalesce(tg_value,'未知') ,coalesce(tg_job,'未知') ,coalesce(tg_feature,'未知'),date_trunc('month',new_acc_dt)
|
||||||
|
) t1
|
||||||
|
left join
|
||||||
|
(
|
||||||
|
select
|
||||||
|
coalesce(tg_play,'未知') as tg_play,coalesce(tg_ver,'未知') as tg_ver,coalesce(tg_value,'未知') as tg_value,coalesce(tg_job,'未知') as tg_job,
|
||||||
|
coalesce(tg_feature,'未知') as tg_feature,date_trunc('month',new_acc_dt) as new_acc_mon,
|
||||||
|
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
|
||||||
|
coalesce(tg_play,'未知') ,coalesce(tg_ver,'未知') ,coalesce(tg_value,'未知') ,coalesce(tg_job,'未知') ,coalesce(tg_feature,'未知'),date_trunc('month',new_acc_dt)
|
||||||
|
) t2 on t1.new_acc_mon=t2.new_acc_mon and t1.tg_play=t2.tg_play and t1.tg_ver=t2.tg_ver and t1.tg_value=t2.tg_value and t1.tg_job=t2.tg_job and t1.tg_feature=t2.tg_feature
|
||||||
|
;
|
||||||
|
|
||||||
|
88
other/Centos-7.sql
Normal file
88
other/Centos-7.sql
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
|
||||||
|
|
||||||
|
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
|
||||||
|
更新镜像源
|
||||||
|
清除缓存:yum clean all
|
||||||
|
生成缓存:yum makecache
|
||||||
|
yum -y makecache update
|
||||||
|
|
||||||
|
|
||||||
|
yum install net-tools - y
|
||||||
|
netstat -tlnp
|
||||||
|
|
||||||
|
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
|
||||||
|
|
||||||
|
vi /etc/profile
|
||||||
|
export JAVA_HOME=/opt/jdk8
|
||||||
|
export PATH=$JAVA_HOME/bin:$PATH
|
||||||
|
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
|
||||||
|
|
||||||
|
/opt/dolphinscheduler-3.2.2/api-server/libs/
|
||||||
|
|
||||||
|
|
||||||
|
export PYTHON_LAUNCHER=/usr/bin/python3
|
||||||
|
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
|
||||||
|
export DATAX_LAUNCHER=/opt/datax/bin/datax.py
|
||||||
|
export PATH=$PYTHON_LAUNCHER:$JAVA_HOME/bin:$DATAX_LAUNCHER:$PATH
|
||||||
|
|
||||||
|
|
||||||
|
python /opt/datax/bin/datax.py /opt/datax/job/job.json
|
||||||
|
|
||||||
|
|
||||||
|
http://yin520.cn:12345/dolphinscheduler/ui
|
||||||
|
yinzhou
|
||||||
|
dolphinscheduler996
|
||||||
|
|
||||||
|
https://note.youdao.com/s/WuYHv1cU
|
||||||
|
这是文档,它可以做sql任务调度,还可以做数据同步,任务监控,还有你上次说的数据质量管理(方式是去跑指定sql) 这个也集成了
|
||||||
|
|
||||||
|
|
||||||
|
开源dolphinscheduler调度器搭建,流程整理
|
||||||
|
|
||||||
|
|
||||||
|
# 解压
|
||||||
|
tar -xvzf apache-dolphinscheduler-*-bin.tar.gz
|
||||||
|
|
||||||
|
|
||||||
|
# 创建用户需使用 root 登录
|
||||||
|
useradd dolphinscheduler
|
||||||
|
|
||||||
|
# 添加密码
|
||||||
|
echo "dolphinscheduler" | passwd --stdin dolphinscheduler
|
||||||
|
|
||||||
|
# 配置 sudo 免密
|
||||||
|
sed -i '$adolphinscheduler ALL=(ALL) NOPASSWD: NOPASSWD: ALL' /etc/sudoers
|
||||||
|
sed -i 's/Defaults requirett/#Defaults requirett/g' /etc/sudoers
|
||||||
|
|
||||||
|
# 修改目录权限,使得部署用户对二进制包解压后的 apache-dolphinscheduler-*-bin 目录有操作权限
|
||||||
|
chown -R dolphinscheduler:dolphinscheduler apache-dolphinscheduler-*-bin
|
||||||
|
chmod -R 755 apache-dolphinscheduler-*-bin
|
||||||
|
|
||||||
|
su dolphinscheduler
|
||||||
|
|
||||||
|
# 一键停止集群所有服务
|
||||||
|
bash /opt/dolphinscheduler-3.2.2/bin/stop-all.sh
|
||||||
|
|
||||||
|
# 一键开启集群所有服务
|
||||||
|
bash /opt/dolphinscheduler-3.2.2/bin/start-all.sh
|
||||||
|
|
||||||
|
|
||||||
|
bash /opt/dolphinscheduler-3.2.2/bin/dolphinscheduler-daemon.sh stop master-server
|
||||||
|
bash /opt/dolphinscheduler-3.2.2/bin/dolphinscheduler-daemon.sh start master-server
|
||||||
|
|
||||||
|
|
||||||
|
pip3 install virtualenv -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||||
|
virtualenv -p python3 /opt/my_python_env
|
||||||
|
source /opt/job/.venv/Scripts/activate
|
||||||
|
deactivate
|
||||||
|
|
||||||
|
|
||||||
|
cd /opt/job/ && source /opt/my_python_env/bin/activate
|
||||||
|
|
||||||
|
source /opt/job/.venv/Scripts/activate
|
||||||
|
pip3 install -r /opt/job/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||||
|
|
||||||
|
python3 -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||||
|
|
||||||
|
pip install psycopg2==2.9.6 -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||||
|
pip3 install wheel -i https://pypi.tuna.tsinghua.edu.cn/simple
|
2
sql笔记/项目.md
Normal file
2
sql笔记/项目.md
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
1.根据 机翻->译文->质检(qc)->终稿 计算相似度,然后相似度比较高的译员记为高质量译员 根据领域,分派任务推送给高质量译员(默认一个译员默认五个领域)
|
||||||
|
2
|
Loading…
x
Reference in New Issue
Block a user