hive sql用户留存计算

select 
	first_day,
	by_day,
	count(orderid) as total_num_of_order
from
(select 
	uuid,
	first_day,
	activate_day,
	orderid,
	datediff(activate_day,first_day) as by_day
from
	(select 
		t1.uuid,
		from_unixtime(unix_timestamp(t1.dt,'yyyymmdd'),'yyyy-mm-dd') as first_day,
		from_unixtime(unix_timestamp(t2.dt,'yyyymmdd'),'yyyy-mm-dd') as activate_day,
		t2.orderid
	from
		(select 
			distinct uuid,
			dt
		from table_new_user
		where installtype = 0 and dt >=20210401) t1 
		left join
		(select 
			distinct uuid,
			dt,
			orderid
		from table_user_action
		where dt >= 20210401) t2 on t1.uuid = t2.uuid
		) as tmp1
	) as tmp2
where first_day = '20210401'
group by first_day,by_day
order by first_day desc, by_day asc
limit 10;

reference:https://www.isky.wang/notes/calcu-user-retention-by-sql/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值