HIVE日活、周活、月活、新增业务指标分析

目录

 

一、前提

二、dws层日活、周活、月活

1、数据的走向分析

2、日活sql

3、dws_uv_detail_day日活跃的数据

4、周活跃sql

5、dws_uv_detail_wk周活跃的数据

6、月活跃的sql:

7、dws_uv_detail_wk月活跃的数据

三、ads层活跃用户数统计

1、活跃用户表的创建

2、活跃用户数的sql


一、前提

数据仓库ods,dwd层搭建完毕,基础数据导入成功。 

 

二、dws层日活、周活、月活

1、数据的走向分析

    dwd_start_log的数据
	zhangsan	sh	2019-02-10
	zhangsan	bj	2019-02-10
	zhangsan	sz	2019-02-10
	lisi	sh	2019-02-10
	lisi	bj	2019-02-10
	lisi	sz	2019-02-10
	wangwu	sh	2019-02-10
	wangwu	bj	2019-02-10
	wangwu	sz	2019-02-10
	zhaoliu	sh	2019-02-11
	zhaoliu	bj	2019-02-11
	zhaoliu	sz	2019-02-11

2、日活sql

select 
	mid_id
	concat_ws('|',collect_set(course)),
	from dwd_start_log
	where dt='2019-02-10'
	group by mid_id;

3、dws_uv_detail_day日活跃的数据

zhangsan |sh|bj|sz 2019-02-10
	zhangsan |sh|bj|sz 2019-02-11
	lisi |sh|bj|sz 2019-02-10
	wangwu |sh|bj|sz 2019-02-10
	zhaoliu |sh|bj|sz 2019-02-11

4、周活跃sql

select 
	mid_id
	concat_ws('|',collect_set(course)),
	date_add(next_day('2019-02-10','mo'),-7) 'moday',
	date_add(next_day('2019-02-10','mo'),-1) 'sunday',
	concat(date_add(next_day('2019-02-10','mo'),-7),'_',date_add(next_day('2019-02-10','mo'),-1)) wk
	from dws_uv_detail_day
	where dt>date_add(next_day('2019-02-10','mo'),-7) and dt < date_add(next_day('2019-02-10','mo'),-1)
	group by mid_id;

5、dws_uv_detail_wk周活跃的数据

    zhangsan |sh|bj|sz|sh|bj|sz 2019-05-06_2019-05-12
	lisi |sh|bj|sz 2019-05-06_2019-05-12
	wangwu |sh|bj|sz 2019-05-06_2019-05-12
	zhaoliu |sh|bj|sz 2019-05-06_2019-05-12

6、月活跃的sql:

select 
	mid_id
	concat_ws('|',collect_set(course)),
	date_format('2019-02-10','yyyy-MM')) mn
	from dws_uv_detail_day
	where date_format('dt','yyyy-MM')) =date_format('2019-02-10','yyyy-MM'))
	group by mid_id;

7、dws_uv_detail_wk月活跃的数据

zhangsan |sh|bj|sz|sh|bj|sz 2019-02
	lisi |sh|bj|sz 2019-02
	wangwu |sh|bj|sz 2019-02
	zhaoliu |sh|bj|sz 2019-02

三、ads层活跃用户数统计

1、活跃用户表的创建

create external table ads_uv_count(
	 dt string,
	 day_count bigint,
	 wk_count bigint,
	 mn_count bigint,
	 is_weekend string,
	 is_monthend string
	)

2、活跃用户数的sql

select
		dt ,
		day_count ,
		wk_count ,
		mn_count ,
		if(next_day(dt,'su')=dt,'Y','N'),
		if(last_day(dt,'yyyy-MM-dd')=dt,'Y','N') 
	from 
	
	(
		select
			dt,
			count(*) ct,
		from dws_uv_detail_day
		where dt=dt
	)t1 
	left join 
	(
		select
			dt,
			count(*) ct,
		from dws_uv_detail_wk
		where wk_dt=concat(,,)
	)t2 on t1.dt=t2.dt
	left join 
	(
		select
			dt,
			count(*) ct,
		from dws_uv_detail_mn
		where mn=date_format(dt,'yyyy-MM')
	)t3 on t1.dt=t3.dt

 

你可能感兴趣的:(数据仓库项目)