Hive留存率统计

新增加的用户表

insert into ta_index_new_user
select channel,toal.client_id,access_time,from_unixtime(unix_timestamp(),’yyyy-MM-dd’) from tm_original_access_log toal
where toal.client_id not in (select tinu.client_id from ta_index_new_user tinu)
and toal.client_id is not null
group by access_time,toal.client_id,channel;

统计留存率统计

insert into ta_index_one_remain
select xinzeng.channel,count(distinct(liucun.client_id)),from_unixtime(unix_timestamp(),’yyyy-MM-dd’) from (select * from tm_original_access_log) xinzeng
inner join
(select * from ta_index_new_user where client_id is not null) liucun
on xinzeng.client_id=liucun.client_id
where day(from_unixtime(cast(xinzeng.access_time as bigint),’yyyy-MM-dd’)) =day(from_unixtime(cast(liucun.access_time as bigint),’yyyy-MM-dd’))+1 group by xinzeng.channel;

你可能感兴趣的:(hive)