题解 | #2021年11月每天新用户的次日留存率#

2021年11月每天新用户的次日留存率

http://www.nowcoder.com/practice/1fc0e75f07434ef5ba4f1fb2aa83a450

思路:

  1. In_timeout_time都算活跃——分别选取为act_date并用**union(而非union all)**连接
  2. 新用户——act_date=latest_date=min(act_date) /min(act_date) over(以uid分类)
  3. 次日留存率:
  • 次日—利用**lead(act_date,1) over (partition by uid order by date)as date1 **把日期列在各自的uid大块内整体向前移一行
  • 次日留存——datediff(date1,act_date)=1
  • 次日留存率——avg(if(datediff(date1,act_date)=1,1,0))(以dt分类)

代码:

  1. act_dateq1
select uid,date(in_time) as act_date
          from tb_user_log
          union 
          select uid,date(out_time) as act_date
          from tb_user_log
order by uid,act_date

alt

  1. 用于判断新用户的latest_date和用于判断次日的date1都以uid分类,可放在一表q2中,此时前者宜选用min()over,这样都不涉及**group by **语句
with q1 as
(select uid,date(in_time) as act_date
          from tb_user_log
          union 
          select uid,date(out_time) as act_date
          from tb_user_log
order by uid,act_date
         )
select uid,act_date,lead(act_date,1) over 
     (partition by uid order by act_date) as date1,
     min(act_date) over (partition by uid) as first_date
     from q1 

alt

  1. 取次日留存率,注意取2021年11月数据,且group by dt
with q1 as
(select uid,date(in_time) as act_date
          from tb_user_log
          union 
          select uid,date(out_time) as act_date
          from tb_user_log
order by uid,act_date
         )
select act_date as dt,
round(avg(if(datediff(date1,act_date)=1,1,0)),2) as uv_left_rate
from
    (select uid,act_date,lead(act_date,1) over 
     (partition by uid order by act_date) as date1,
     min(act_date) over (partition by uid) as first_date
     from q1 
    ) as q2
where act_date=first_date and year(act_date)=2021 and month(act_date)=11
group by dt
order by dt

alt

全部评论

相关推荐

争当牛马还争不上
码农索隆:1.把简历改哈 2.猛投,狠投 3.把基础打牢 这样你在有机会的时候,才能抓住
点赞 评论 收藏
分享
强大的马里奥:不太可能,我校计算机硕士就业率99%
点赞 评论 收藏
分享
06-15 02:05
已编辑
南昌航空大学 数据分析师
Eason三木:你如果想干技术岗,那几个发公众号合唱比赛的经历就去掉,优秀团员去掉,求职没用。然后CET4这种不是奖项,是技能,放到下面的专业技能里或者单独列一个英语能力。 另外好好改改你的排版,首行缩进完全没有必要,行间距好好调调,别让字和标题背景黏在一起,你下面说能做高质量PPT你得展现出来啊,你这简历排版我用PPT做的都能比你做的好。 然后自我评价,你如果要干数据工程师,抗压能力强最起码得有吧。
简历中的项目经历要怎么写
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务