当前位置:   article > 正文

Hive sql 面试题-计算3天沉默用户数

Hive sql 面试题-计算3天沉默用户数

表名称:user
uid login_time
1 ‘2023-04-01 12:02:00’
1 ‘2023-04-01 13:04:00’
3 ‘2023-04-01 23:02:00’
1 ‘2023-04-02 23:02:00’
1 ‘2023-04-03 23:02:00’
2 ‘2023-04-07 23:02:00’

select count(distinct if(cha_date > 3,uid,null )) as '超过3天',
       count(distinct if(cha_date > 5,uid,null )) as '超过5天'
from (
    select uid ,
           login_time,
           datediff(date_sub(login_time ,1 ) , LAG(login_time,1,login_time) over (partition by uid order by desc )) as cha_date,
           LAG(login_time,1,login_time )  over(partition by uid order by desc ) as pre_time
    from (
      select uid,date_format(login_time,'%Y-%m-%d') as login_time
      from user
      group by uid
    ) t1
) t2 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/711273
推荐阅读
相关标签
  

闽ICP备14008679号