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

使用的日历类 add方法 和simpledateformat 将long类型的 定义多个重载方法 获取返回值int类型 或者long类型 进行时间判断即可
getdaybegin(天开始),比如2017-08-08这一天的createtime为15288888888888 获取到 152888880000(代表20170808 00:00:00)当天开始的凌晨 
getWeekbegin,getMonthgin 同上道理
 1.过去的五周(包含本周)某个app每周的周活跃用户数
注意,如果能够界定分区区间的话,务必要进行分区限定查询。
20170501
ym/day/hm
//过去的五周,每周的活跃数
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) ;
2.最近的六个月(包含本月)每月的月活跃数。
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') ;
3.沉默用户数
3.1)查询今天沉默用户数 //某个设备 启动时间 在今天(本周、本月) 只有一次 ,后续在无启动
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
4.启动次数
4.1)今天app的启动次数
启动次数类似于活跃用户数,活跃用户数去重,启动次数不需要去重。
select count(*) from ext_startup_logs where appid = 'sdk34734' and ym = formattime(getdaybegin(),'yyyyMM') and day = formattime(getdaybegin(),'dd');
5.版本分布
5.1)今天appid为34734的不同版本的活跃用户数。
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 ; 5.2)本周内每天各版本日活
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 [用户构成分析]
1.本周回流用户 上周未启动,本周启动了的用 必须当使用not in 子查询和后续查询都必须加入别名
select
distinct a.deviceid
from ext_startup_logs a
where a.appid = 'sdk34734' and concat(a.ym,a.day) >= formattime(getweekbegin(),'yyyyMMdd') and a.deviceid not in (
select
distinct t.deviceid
from ext_startup_logs t
where t.appid = 'sdk34734' and concat(t.ym,t.day) >= formattime(getweekbegin(-1),'yyyyMMdd') and concat(t.ym,t.day) < formattime(getweekbegin(),'yyyyMMdd')
) 2.连续活跃n周 连续三周活跃 2018101 20181008 20181016 去掉重有三次就是活跃
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 3.忠诚用户 连续活跃5周的
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 4.连续活跃用户 连续活跃n周
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 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')) 5.近期流失用户
最近2、3、4都没有启动过app.
查询所有用户访问的时间的max,max不能落在
//四周内流失
select
distinct(deviceid)
from ext_startup_logs
where appid='#'
and concat(ym,day) >= formattime(getweekbegin(-4),'yyyyMMdd')
and concat(ym,day) < formattime(getweekbegin(-3),'yyyyMMdd')
and deviceid not in (
select
distinct(t.deviceid)
from ext_startup_logs t
where t.appid=''
and concat(t.ym,t.day) >= formattime(getweekbegin(-3),'yyyyMMdd') )
union
//三周内流失
select
distinct(deviceid)
from ext_startup_logs
where appid='#'
and concat(ym,day) >= formattime(getweekbegin(-3),'yyyyMMdd')
and concat(ym,day) < formattime(getweekbegin(-2),'yyyyMMdd')
and deviceid not in (
select
distinct(t.deviceid)
from ext_startup_logs t
where t.appid=''
and concat(t.ym,t.day) >= formattime(getweekbegin(-2),'yyyyMMdd') )
union
//两周内流失
select
distinct(deviceid)
from ext_startup_logs
where appid='#'
and concat(ym,day) >= formattime(getweekbegin(-2),'yyyyMMdd')
and concat(ym,day) < formattime(getweekbegin(-1),'yyyyMMdd')
and deviceid not in (
select
distinct(t.deviceid)
from ext_startup_logs t
where t.appid=''
and concat(t.ym,t.day) >= formattime(getweekbegin(-1),'yyyyMMdd')
) [留存分析]
1.留存用户
周留存用户。上周新增的用户在本周还使用的
select
distinct(a.deviceid)
from ext_startup_logs a
where a.appid = 'sdk34734'
and concat(a.ym,a.day) >= formattime(getweekbegin(-1),'yyyyMMdd')
and concat(a.ym,a.day) < formattime(getweekbegin(),'yyyyMMdd')
and a.deviceid in (
select distinct(t.deviceid)
from (
select tt.deviceid , min(tt.createdatms) mintime
from ext_startup_logs tt
where tt.appid = 'sdk34734'
group by tt.deviceid having mintime >= getweekbegin(-2) and mintime < getweekbegin(-1)
) t
) 2.用户的新鲜度
新鲜度 = 某段时间的新增用户数/某段时间的活跃的老用户数 .
//今天活跃用户 m = select count(distinct(t.deviceid))
from ext_startup_logs where concat(ym,day) = formattime(getdaybegin(),'yyyyMMdd') and appid = ... ;
//今天新增用户
n = select count(distinct(t.deviceid))
from (
select tt.deviceid , min(tt.createdatms) mintime
from ext_startup_logs tt
where tt.appid = 'sdk34734'
group by tt.deviceid having mintime >= getdaybegin(0)
) 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. 算法 -- 求最长公共字符串&PHP

    https://blog.csdn.net/hongyuancao/article/details/83308093 本文是利用PHP,求最长公共字符串.思路:利用动态规划和矩阵的思想. 动态规划:就 ...

  2. Ubuntu Server16.04 配置网卡

    展示全部启动网卡 $ ifconfig 配置网卡 $ sudo vi /etc/network/interfaces auto enp2s0 iface enp2s0 inet static addr ...

  3. 以太坊中的账户、交易、Gas和区块Gas Limit等概念

    什么是账户 以太坊账户与我们所知的账户概念有一定相似之处,却又有很大的区别,更不同于比特币中UTXO. 账户分两类: - 外部拥有账户(EOA),也就是普通账户 - 合约账户 普通账户 所谓的普通账户 ...

  4. redis集群redis-cloud搭建

    Redis集群中至少应该有三个节点.要保证集群的高可用,需要每个节点有一个备份机.Redis集群至少需要6台服务器. 搭建伪分布式.可以使用一台虚拟机运行6个redis实例.需要修改redis的端口号 ...

  5. [LeetCode] 111. Minimum Depth of Binary Tree_Easy tag:DFS

    Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...

  6. 从现在开始,这是一个IT博客。

    从现在开始,删除以前的点点滴滴,一心做个IT人.

  7. VirtualBox如何扩展虚拟机Ubuntu的硬盘容量-转

    https://blog.csdn.net/ouyang_peng/article/details/53261599 摘录要点: 扩展 VBoxManage modifyhd YOUR_HARD_DI ...

  8. MSSqlServer 主从同步复制原理(发布/订阅)

    基本模型 1.发布类型: 快照发布:用于为事务复制和合并复制提供初始数据集:在适合数据完全刷新时也可以使用快照复制.利用这三种复制,SQL Server 提供功能强大且灵活的系统,以便使企业范围内的数 ...

  9. docker每次都重新拉取远程镜像的问题

    将镜像上传到远程之后,dockerfile按理来说只需一次拉取远程镜像就好了,之后每次都是使用第一次拉取的远程镜像. 但是实际上出现的问题是:dockerfile每次都从远程拉取镜像,浪费了资源和时间 ...

  10. js中变量提升(一个是变量,一个是函数表达式都会存在变量提升,函数声明不存在)

    一.变量提升 在ES6之前,JavaScript没有块级作用域(一对花括号{}即为一个块级作用域),只有全局作用域和函数作用域.变量提升即将变量声明提升到它所在作用域的最开始的部分.上个简历的例子如: ...