9(10)第5章需求二:轉化率及漏斗分析10

第5章需求二:轉化率及漏斗分析
5.2ADS層之新增用戶佔日活躍用戶比率
5.2.1 建表語句

hive (gmall)>
drop table if exists ads_user_convert_day;
create external table ads_user_convert_day(
dt string COMMENT ‘統計日期’,
uv_m_count bigint COMMENT ‘當日活躍設備’,
new_m_count bigint COMMENT ‘當日新增設備’,
new_m_ratio decimal(10,2) COMMENT ‘當日新增佔日活的比率’
) COMMENT ‘轉化率’
row format delimited fields terminated by ‘\t’
location ‘/warehouse/gmall/ads/ads_user_convert_day/’
;
5.2.2數據導入

1)數據導入
hive (gmall)>
insert into table ads_user_convert_day
select
‘2019-02-10’,
sum(uc.dc) sum_dc,
sum(uc.nmc) sum_nmc,
cast(sum( uc.nmc)/sum( uc.dc)*100 as decimal(10,2)) new_m_ratio
from
(
select
day_count dc,
0 nmc
from ads_uv_count
where dt=‘2019-02-10’
union all
select
0 dc,
new_mid_count nmc
from ads_new_mid_count
where create_date=‘2019-02-10’
)uc;
2)查看導入數據
hive (gmall)>
select * from ads_user_convert_day;

5.3ADS層之用戶行爲漏斗分析
5.3.1 建表語句

hive (gmall)>
drop table if exists ads_user_action_convert_day;
create external table ads_user_action_convert_day(
dt string COMMENT ‘統計日期’,
total_visitor_m_count bigint COMMENT ‘總訪問人數’,
order_u_count bigint COMMENT ‘下單人數’,
visitor2order_convert_ratio decimal(10,2) COMMENT ‘訪問到下單轉化率’,
payment_u_count bigint COMMENT ‘支付人數’,
order2payment_convert_ratio decimal(10,2) COMMENT ‘下單到支付的轉化率’
) COMMENT ‘用戶行爲漏斗分析’
row format delimited fields terminated by ‘\t’
location ‘/warehouse/gmall/ads/ads_user_action_convert_day/’
;
5.3.2 數據導入

1)數據導入
hive (gmall)>
insert into table ads_user_action_convert_day
select
‘2019-02-10’,
uv.day_count,
ua.order_count,
cast(ua.order_count/uv.day_count as decimal(10,2)) visitor2order_convert_ratio,
ua.payment_count,
cast(ua.payment_count/ua.order_count as decimal(10,2)) order2payment_convert_ratio
from
(
select
sum(if(order_count>0,1,0)) order_count,
sum(if(payment_count>0,1,0)) payment_count
from dws_user_action
where dt=‘2019-02-10’
)ua, ads_uv_count uv
where uv.dt=‘2019-02-10’
;
2)查詢導入數據
hive (gmall)> select * from ads_user_action_convert_day;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章