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;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值