画像标签累计类型如何计算

我们在开发画像标签的过程中会遇到如下的维度:

  1. 客户首次进入app**模块的日期
  2. 客户最后一次进入app**模块的日期
  3. 客户在app**模块的累计的活跃时长
  4. 客户在app**模块的累计活跃次数
  5. 客户在app**模块的累计活跃天数

核心思想是用用今天的数据和历史数据滚动式迭代的方式计算,示例代码如下:

任务A存储着用户当天的数据;

create table A(

phone_no string comment ‘客户手机号码’

,active_duration_1day string comment  ‘当天活跃时长’

,active_cnt_1day string comment '当天活跃次数'

) partition by (day string );

任务B从任务A中取数,实现以上的标签计算:

insert overwrite table B partition(day='date' )
 select 
   phone_no                   as phone_no             --客户手机号码
  ,min(first_enter_date    )  as first_enter_date     --首次进入日期
  ,max(last_enter_date     )  as last_enter_date      --最后一次进入日期
  ,sum( active_duration_acc)  as active_duration_acc  --累计活跃时长
  ,sum(active_cnt_acc      )  as active_cnt_acc       --累计活跃次数
  ,sum( active_days_acc    )  as active_days_acc      --累计活跃天数
 from 
  (select 
    phone_no
    ,first_enter_date
    ,last_enter_date
    ,active_duration_acc 
    ,active_cnt_acc
    ,active_days_acc
  FROM B where day=date_sub(date,1)
  union all
  select 
    phone_no
    'date' as first_enter_date
    ,'date' as last_enter_date
    ,active_duration_1day as active_duration_acc 
    ,active_cnt_1day  as active_cnt_acc
    ,'1' as active_days_acc 
  from A where day='date'
  )t group by phone_no

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值