1.  
  1.  

 很简单的sql 用户分析语句 :只要自定义简单的udf函数 获取统计时间createdatms字段的

  1. 使用的日历类 add方法 simpledateformat long类型的 定义多个重载方法 获取返回值int类型 或者long类型 进行时间判断即可
  1. getdaybegin(天开始),比如2017-08-08这一天的createtime15288888888888 获取到 152888880000(代表20170808 00:00:00)当天开始的凌晨
    getWeekbegingetMonthgin 同上道理
  1. 1.过去的五周(包含本周)某个app每周的周活跃用户数
  2. 注意,如果能够界定分区区间的话,务必要进行分区限定查询。
  3. 20170501
  4. ym/day/hm
  5. //过去的五周,每周的活跃数
  6. select formattime(createdatms,'yyyyMMdd',0) stdate, count(distinct deviceid) stcount from ext_startup_logs where concat(ym,day)>=formattime(getweekbegin(-4),'yyyyMMdd') and appid ='sdk34734' group by formattime(createdatms,'yyyyMMdd',0) ;
  7. 2.最近的六个月(包含本月)每月的月活跃数。
  8. select formattime(createdatms,'yyyyMM') stdate, count(distinct deviceid) stcount from ext_startup_logs where ym >= formattime(getmonthbegin(-5),'yyyyMM') and appid ='sdk34734' group by formattime(createdatms,'yyyyMM') ;
  9. 3.沉默用户数
  10. 3.1)查询今天沉默用户数 //某个设备 启动时间 在今天(本周、本月) 只有一次 ,后续在无启动
  11. select count(*) from (select deviceid , count(createdatms) dcount,min(createdatms) dmin from ext_startup_logswhere appid = 'sdk34734' group by deviceid having dcount = 1 and min(createdatms) > getdaybegin(-1)) t
  12. 4.启动次数
  13. 4.1)今天app的启动次数
  14. 启动次数类似于活跃用户数,活跃用户数去重,启动次数不需要去重。
  15. select count(*) from ext_startup_logs where appid = 'sdk34734' and ym = formattime(getdaybegin(),'yyyyMM') and day = formattime(getdaybegin(),'dd');
  16. 5.版本分布
  17. 5.1)今天appid34734的不同版本的活跃用户数。
  18. select appversion,count(distinct deviceid) from ext_startup_logs where appid = 'sdk34734' and ym = formattime(getdaybegin(),'yyyyMM') and day = formattime(getdaybegin(),'dd') group by appversion ;
  19.  
  20. 5.2)本周内每天各版本日活
  21. select formattime(createdatms,'yyyyMMdd'),appversion , count(distinct deviceid) from ext_startup_logs where appid = 'sdk34734' and concat(ym,day) >= formattime(getweekbegin(),'yyyyMMdd') group by formattime(createdatms,'yyyyMMdd') , appversion
  22.  
  23. [用户构成分析]
  24. 1.本周回流用户 上周未启动,本周启动了的用 必须当使用not in 子查询和后续查询都必须加入别名
  25. select
  26. distinct a.deviceid
  27. from ext_startup_logs a
  28. where a.appid = 'sdk34734' and concat(a.ym,a.day) >= formattime(getweekbegin(),'yyyyMMdd') and a.deviceid not in (
  29. select
  30. distinct t.deviceid
  31. from ext_startup_logs t
  32. where t.appid = 'sdk34734' and concat(t.ym,t.day) >= formattime(getweekbegin(-1),'yyyyMMdd') and concat(t.ym,t.day) < formattime(getweekbegin(),'yyyyMMdd')
  33. )
  34.  
  35. 2.连续活跃n 连续三周活跃 2018101 20181008 20181016 去掉重有三次就是活跃
  36. select deviceid , count(distinct(formattime(createdatms,'yyyyMMdd',0))) c from ext_startup_logs where appid = 'sdk34734' and concat(ym,day) >= formattime(getweekbegin(-2),'yyyyMMdd') group by deviceid having c = 3
  37.  
  38. 3.忠诚用户 连续活跃5周的
  39. select deviceid , count(distinct(formattime(createdatms,'yyyyMMdd',0))) c from ext_startup_logs where appid = 'sdk34734' and concat(ym,day) >= formattime(getweekbegin(-4),'yyyyMMdd') group by deviceid having c = 5
  40.  
  41. 4.连续活跃用户 连续活跃n
  42. select deviceid , count(distinct(formattime(createdatms,'yyyyMMdd',0))) c from ext_startup_logs where appid = 'sdk34734' and concat(ym,day) >= formattime(getweekbegin(-1),'yyyyMMdd') group by deviceid having c = 2
  43.  
  44. select distinct(a.deviceid) from ext_startup_logs a where concat(a.ym,a.day) < formattime(getweekbegin(-4),'yyyyMMdd') and deviceid not in ( select distinct(t.deviceid) from ext_startup_logs t where concat(t.ym,t.day)>=formattime(getweekbegin(-4),'yyyyMMdd'))
  45.  
  46. 5.近期流失用户
  47. 最近234都没有启动过app.
  48. 查询所有用户访问的时间的max,max不能落在
  49. //四周内流失
  50. select
  51. distinct(deviceid)
  52. from ext_startup_logs
  53. where appid='#'
  54. and concat(ym,day) >= formattime(getweekbegin(-4),'yyyyMMdd')
  55. and concat(ym,day) < formattime(getweekbegin(-3),'yyyyMMdd')
  56. and deviceid not in (
  57. select
  58. distinct(t.deviceid)
  59. from ext_startup_logs t
  60. where t.appid=''
  61. and concat(t.ym,t.day) >= formattime(getweekbegin(-3),'yyyyMMdd')
  62.  
  63. )
  64. union
  65. //三周内流失
  66. select
  67. distinct(deviceid)
  68. from ext_startup_logs
  69. where appid='#'
  70. and concat(ym,day) >= formattime(getweekbegin(-3),'yyyyMMdd')
  71. and concat(ym,day) < formattime(getweekbegin(-2),'yyyyMMdd')
  72. and deviceid not in (
  73. select
  74. distinct(t.deviceid)
  75. from ext_startup_logs t
  76. where t.appid=''
  77. and concat(t.ym,t.day) >= formattime(getweekbegin(-2),'yyyyMMdd')
  78.  
  79. )
  80. union
  81. //两周内流失
  82. select
  83. distinct(deviceid)
  84. from ext_startup_logs
  85. where appid='#'
  86. and concat(ym,day) >= formattime(getweekbegin(-2),'yyyyMMdd')
  87. and concat(ym,day) < formattime(getweekbegin(-1),'yyyyMMdd')
  88. and deviceid not in (
  89. select
  90. distinct(t.deviceid)
  91. from ext_startup_logs t
  92. where t.appid=''
  93. and concat(t.ym,t.day) >= formattime(getweekbegin(-1),'yyyyMMdd')
  94. )
  95.  
  96. [留存分析]
  97. 1.留存用户
  98. 周留存用户。上周新增的用户在本周还使用的
  99. select
  100. distinct(a.deviceid)
  101. from ext_startup_logs a
  102. where a.appid = 'sdk34734'
  103. and concat(a.ym,a.day) >= formattime(getweekbegin(-1),'yyyyMMdd')
  104. and concat(a.ym,a.day) < formattime(getweekbegin(),'yyyyMMdd')
  105. and a.deviceid in (
  106. select distinct(t.deviceid)
  107. from (
  108. select tt.deviceid , min(tt.createdatms) mintime
  109. from ext_startup_logs tt
  110. where tt.appid = 'sdk34734'
  111. group by tt.deviceid having mintime >= getweekbegin(-2) and mintime < getweekbegin(-1)
  112. ) t
  113. )
  114.  
  115. 2.用户的新鲜度
  116. 新鲜度 = 某段时间的新增用户数/某段时间的活跃的老用户数 .
  117. //今天活跃用户
  118.  
  119. m = select count(distinct(t.deviceid))
  120. from ext_startup_logs where concat(ym,day) = formattime(getdaybegin(),'yyyyMMdd') and appid = ... ;
  121. //今天新增用户
  122. n = select count(distinct(t.deviceid))
  123. from (
  124. select tt.deviceid , min(tt.createdatms) mintime
  125. from ext_startup_logs tt
  126. where tt.appid = 'sdk34734'
  127. group by tt.deviceid having mintime >= getdaybegin(0)
  128. ) t

hive 用户行为分析(活跃。启动,留存,回访,新增)的一些经典sql的更多相关文章

  1. Hadoop项目实战-用户行为分析之编码实践

    1.概述 本课程的视频教程地址:<用户行为分析之编码实践> 本课程以用户行为分析案例为基础,带着大家去完成对各个KPI的编码工作,以及应用调度工作,让大家通过本课程掌握Hadoop项目的编 ...

  2. 用实战玩转pandas数据分析(一)——用户消费行为分析(python)

      CD商品订单数据的分析总结.根据订单数据(用户的消费记录),从时间维度和用户维度,分析该网站用户的消费行为.通过此案例,总结订单数据的一些共性,能通过用户的消费记录挖掘出对业务有用的信息.对其他产 ...

  3. Appium Server 源码分析之启动运行Express http服务器

    通过上一个系列Appium Android Bootstrap源码分析我们了解到了appium在安卓目标机器上是如何通过bootstrap这个服务来接收appium从pc端发送过来的命令,并最终使用u ...

  4. Hadoop项目实战-用户行为分析之应用概述(一)

    1.概述 本课程的视频教程地址:<Hadoop 回顾> 好的,下面就开始本篇教程的内容分享,本篇教程我为大家介绍我们要做一个什么样的Hadoop项目,并且对Hadoop项目的基本特点和其中 ...

  5. Linux内核源码分析--内核启动之(5)Image内核启动(rest_init函数)(Linux-3.0 ARMv7)【转】

    前面粗略分析start_kernel函数,此函数中基本上是对内存管理和各子系统的数据结构初始化.在内核初始化函数start_kernel执行到最后,就是调用rest_init函数,这个函数的主要使命就 ...

  6. Linux内核源码分析--内核启动之(6)Image内核启动(do_basic_setup函数)(Linux-3.0 ARMv7)【转】

    原文地址:Linux内核源码分析--内核启动之(6)Image内核启动(do_basic_setup函数)(Linux-3.0 ARMv7) 作者:tekkamanninja 转自:http://bl ...

  7. React Native超简单完整示例-tabs、页面导航、热更新、用户行为分析

    初学React Native,如果没有人指引,会发现好多东西无从下手,但当有人指引后,会发现其实很简单.这也是本人写这篇博客的主要原因,希望能帮到初学者. 本文不会介绍如何搭建开发环境,如果你还没有搭 ...

  8. 商业智能BI与用户行为分析的联系

    ​什么是BI? BI(Business Intelligence)即商业智能,它是一套完整的解决方案,用来将企业中现有的数据进行有效的整合,分析利用企业已有的各种商用数据来了解企业的经营状况和外部环境 ...

  9. 如何排查sharepoint2010用户配置文件同步服务启动问题

    用户配置文件同步服务与 Microsoft Forefront Identity Manager (FIM) 交互,以与外部系统(如目录服务和业务系统)同步配置文件信息.启用用户配置文件同步服务时,将 ...

随机推荐

  1. 20165236 实验二 《Java面向对象程序设计》实验报告

    20165236 实验二<Java面向对象程序设计>实验报告 姓名:郭金涛       学号:20165236      课程:Java程序设计 指导老师:娄嘉鹏       实验时间:2 ...

  2. equals和contains的区别

    equals只能判断两个变量的值是否相等.contains常用与集合中判断某个对象是否含有这个元素equals是需要两个对象完全相同才会返回true,而contains是要循环遍历容器里的所有内容后判 ...

  3. linux中cmake语法的学习

    在linux 下进行开发很多人选择编写makefile 文件进行项目环境搭建,而makefile 文件依赖关系复杂,工作量很大,搞的人头很大.常常,写代码,效率才是王道.这里还有自动化的项目构建工具C ...

  4. Centos7 zookeeper单机/集群安装详解和开机自启

    ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件.它是一个为分布式应用提供一致性服务的软件,提供的功 ...

  5. AC自动机模板2

    题目链接:https://www.luogu.org/problemnew/show/P3796 #include <cstdio> #include <cmath> #inc ...

  6. pd.concat/merge/join

    pandas的拼接分为两种: 级联:pd.concat, pd.append 合并:pd.merge, pd.join 一.回顾numpy.concatenate 生成1个6*3的矩阵,一个2*3的矩 ...

  7. 阿里云esc服务器上部署java项目

    文章中使用centos(6和7版本).Xshell.Xftp 因为部署过程直接从操作服务器开始,如果你还没有连接好服务器请参考http://blog.csdn.net/ctrlxv/article/d ...

  8. 笔记 : Ubuntu部署LNMP环境

    一.准备与安装 1. 安装PHP7.1 #添加php源 :~$ sudo add-apt-repository ppa:ondrej/php #更新apt数据,载入php源数据 :~$ sudo ap ...

  9. Mysql由浅入深

      1. Mysql的安装方式 1. yum安装mysql 适合对数据库要求不太高的场合,例如:并发不大,公司内部,企业内部. 1. 官网下载yum源,wget https://dev.mysql.c ...

  10. Thinkphp 框架

    核心函数库:   配置文件:     语言包  :  核心资源库:入口文件 核心配置文件 系统行为目录:功能目录:核心文件:摸板类文件目录