19 友盟项目--统计新增用户---日新增、周新增、月新增--创建表并插入选择出的数据

新增用户---全表扫描---启动时间的最小值所在的天
各个维度下---with cube
 
昨日新增---第一次启动时间(启动时间最小值)在昨天的设备id
stat_new_day.sql
复制代码
use big12_umeng ;
create table if not exists stat_new_day(
  day string ,
  appid string,
  appplatform string,
  brand string ,
  devicestyle string,
  ostype string ,
  appversion string ,
  cnt int
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
lines terminated by '\n';

insert into table stat_new_day
SELECT
  '2018/08/02' ,
  t.appid ,
  t.appversion ,
  t.appplatform,
  t.brand ,
  t.devicestyle,
  t.ostype ,
  count(t.deviceid) cnt
FROM
  (
    select
      appid ,
      appplatform,
      brand ,
      devicestyle,
      ostype ,
      appversion ,
      deviceid ,
      min(createdatms) firsttime
    from
      appstartuplogs
    group BY
      appid ,
      appplatform,
      brand ,
      devicestyle,
      ostype ,
      appversion,
      deviceid
    with cube
  )t
WHERE
  t.appid is not NULL
  and t.deviceid is not null
  and formatbyday(t.firsttime , 0 , 'yyyy/MM/dd')  = '2018/08/02'
group by
    t.appid ,
    t.appversion ,
    t.appplatform,
    t.brand ,
    t.devicestyle,
    t.ostype
order BY
    t.appid ,
    t.appversion ,
    t.appplatform,
    t.brand ,
    t.devicestyle,
    t.ostype
stat_new_day.sql 昨日新增用户
复制代码

 

周增---从日新增表中 --> 这周内每天新增数  的总和
stat_new_week.sql
复制代码
use big12_umeng ;
create table if not exists stat_new_week(
  day string ,
  appid string,
  appplatform string,
  brand string ,
  devicestyle string,
  ostype string ,
  appversion string ,
  cnt int
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
lines terminated by '\n';

insert into table stat_new_week
SELECT
  appid ,
  appversion ,
  appplatform,
  brand ,
  devicestyle,
  ostype ,
  sum(cnt) cnt
FROM
  stat_new_day
WHERE
  formatbyweek(day ,'yyyy/MM/dd' , 0 , 'yyyy/MM/dd') = formatbyweek('2018/07/31' ,'yyyy/MM/dd' , 0 , 'yyyy/MM/dd')
group by
  appid ,
  appversion ,
  appplatform,
  brand ,
  devicestyle,
  ostype
stat_new_week.sql 周新增用户数
复制代码

 

 
月增---从日新增表中 --> 这月内每天新增数  的总和
stat_new_month.sql
复制代码
use big12_umeng ;
create table if not exists stat_new_month(
  month string ,
  appid string,
  appplatform string,
  brand string ,
  devicestyle string,
  ostype string ,
  appversion string ,
  cnt int
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
lines terminated by '\n';
insert into table stat_new_month
SELECT
  '201808' ,
  appid ,
  appversion ,
  appplatform,
  brand ,
  devicestyle,
  ostype ,
  sum(cnt) cnt
FROM
  stat_new_day
WHERE
  formatbymonth(day ,'yyyy/MM' , 0 , 'yyyy/MM') = '2018/08'
group by
  appid ,
  appversion ,
  appplatform,
  brand ,
  devicestyle,
  ostype
stat_new_month.sql 月新增用户
复制代码

 

 

posted @   star521  阅读(1653)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
点击右上角即可分享
微信分享提示