15. 数据仓库分层之DWS层、ADS层--沉默用户数

沉默用户数:只在安装当天启动过,且启动时间在一周(或月)前。
  1. DWS层使用日活明细表作为数据
  2. ADS层沉默设备数表。

    hive (gmall)>
    drop table if exists ads_slient_count;
    create external table ads_slient_count( 
       `dt` string COMMENT '统计日期',
       `slient_count` bigint COMMENT '沉默设备数'
    ) 
    row format delimited fields terminated by '\t'
    location '/warehouse/gmall/ads/ads_slient_count';
  3. 导入数据

    insert into table ads_slient_count
    select
       '2020-02-03',
       count(*)
    from 
    (
       select mid_id
       from dws_uv_detail_day
       where dt<='2020-02-03'
       group by mid_id
       having count(*)=1 
       and min(dt)<=date_add('2020-02-03',-7)
    )t1;
  4. 查询

    hive (gmall)> select * from ads_slient_count;

你可能感兴趣的:(数据仓库,hive)