9(17)8.3 ADS層17

8.3 ADS層
8.3.1 留存用戶數
1)建表語句
hive (gmall)>
drop table if exists ads_user_retention_day_count;

create external table ads_user_retention_day_count

(

create_date string comment ‘設備新增日期’,

retention_day int comment ‘截止當前日期留存天數’,

retention_count bigint comment ‘留存數量’

) COMMENT ‘每日用戶留存情況’

row format delimited fields terminated by ‘\t’

location ‘/warehouse/gmall/ads/ads_user_retention_day_count/’;

2)導入數據
hive (gmall)>
insert into table ads_user_retention_day_count
select
create_date,
retention_day,
count(*) retention_count
from dws_user_retention_day
where dt=‘2019-02-11’
group by create_date,retention_day;
3)查詢導入數據
hive (gmall)> select * from ads_user_retention_day_count;

8.3.2 留存用戶比率

1)建表語句
hive (gmall)>
drop table if exists ads_user_retention_day_rate;

create external table ads_user_retention_day_rate

(

 `stat_date` string comment '統計日期',

 `create_date` string comment '設備新增日期',

 `retention_day` int comment '截止當前日期留存天數',

 `retention_count` bigint comment '留存數量',

 `new_mid_count` bigint comment '當日設備新增數量',

 `retention_ratio` decimal(10,2) comment '留存率'

) COMMENT ‘每日用戶留存情況’

row format delimited fields terminated by ‘\t’

location ‘/warehouse/gmall/ads/ads_user_retention_day_rate/’;

2)導入數據
hive (gmall)>
insert into table ads_user_retention_day_rate
select
‘2019-02-11’,
ur.create_date,
ur.retention_day,
ur.retention_count,
nc.new_mid_count,
ur.retention_count/nc.new_mid_count100
from
(
select
create_date,
retention_day,
count(
) retention_count
from dws_user_retention_day
where dt=‘2019-02-11’
group by create_date,retention_day
) ur join ads_new_mid_count nc on nc.create_date=ur.create_date;
3)查詢導入數據
hive (gmall)>select * from ads_user_retention_day_rate;

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