9(12)6.2 ADS層12

6.2 ADS層
目標:當日、當週、當月活躍設備數
6.2.1 活躍設備數

drop table if exists ads_uv_count;
create external table ads_uv_count(
dt string COMMENT ‘統計日期’,
day_count bigint COMMENT ‘當日用戶數量’,
wk_count bigint COMMENT ‘當週用戶數量’,
mn_count bigint COMMENT ‘當月用戶數量’,
is_weekend string COMMENT ‘Y,N是否是週末,用於得到本週最終結果’,
is_monthend string COMMENT ‘Y,N是否是月末,用於得到本月最終結果’
) COMMENT ‘活躍設備數’
row format delimited fields terminated by ‘\t’
location ‘/warehouse/gmall/ads/ads_uv_count/’
;
2)導入數據
hive (gmall)>
insert into table ads_uv_count
select
‘2019-02-10’ dt,
daycount.ct,
wkcount.ct,
mncount.ct,
if(date_add(next_day(‘2019-02-10’,‘MO’),-1)=‘2019-02-10’,‘Y’,‘N’) ,
if(last_day(‘2019-02-10’)=‘2019-02-10’,‘Y’,‘N’)
from
(
select
‘2019-02-10’ dt,
count() ct
from dws_uv_detail_day
where dt=‘2019-02-10’
)daycount join
(
select
‘2019-02-10’ dt,
count (
) ct
from dws_uv_detail_wk
where wk_dt=concat(date_add(next_day(‘2019-02-10’,‘MO’),-7),’_’ ,date_add(next_day(‘2019-02-10’,‘MO’),-1) )
) wkcount on daycount.dt=wkcount.dt
join
(
select
‘2019-02-10’ dt,
count (*) ct
from dws_uv_detail_mn
where mn=date_format(‘2019-02-10’,‘yyyy-MM’)
)mncount on daycount.dt=mncount.dt
;
3)查詢導入結果
hive (gmall)> select * from ads_uv_count ;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章