数仓搭建-ADS层

设备主题

活跃设备数(日、周、月)

需求定义:
日活:当日活跃的设备数
周活:当周活跃的设备数
月活:当月活跃的设备数
在这里插入图片描述

每日新增设备

在这里插入图片描述

沉默用户数

需求定义:
沉默用户:只在安装当天启动过,且启动时间是在 7 天前
在这里插入图片描述

本周回流用户数

需求定义:
本周回流用户:上周未活跃,本周活跃的设备,且不是本周新增设备
DWT层拿不到历史数据,所以往DWS拿数据
在这里插入图片描述
解释一下最后一排为啥where last_wk.mid_id=null
在这里插入图片描述

流失用户数

需求定义:
流失用户:最近 7 天未活跃的设备
在这里插入图片描述

留存率

在这里插入图片描述
在这里插入图片描述

最近连续三周活跃用户数

在这里插入图片描述
解释having count(*)=3 因为三周所以三个1
在这里插入图片描述

最近七天内连续三天活跃用户数

思路一 根据dt-rank来算相同的时间
在这里插入图片描述
在这里插入图片描述
思路二 dt-lead=2说明三天连续
在这里插入图片描述
在这里插入图片描述

会员主题

会员主题信息

会员新鲜度=新增会员数/活跃会员数
在这里插入图片描述

漏斗分析

统计“浏览->购物车->下单->支付”的转化
思路:统计各个行为的人数,然后计算比值。
在这里插入图片描述

商品主题

商品个数信息

sku不去重 spu要去重 在业务中尽量不要使用count(distinct(spu))
在这里插入图片描述

商品销量排名

求前十
在这里插入图片描述

商品收藏排名

在这里插入图片描述

商品加入购物车排名

在这里插入图片描述

商品退款率排名(最近 30 天)

在这里插入图片描述

商品差评率

在这里插入图片描述

营销主题(用户+商品+购买行为)

下单数目统计

需求分析:统计每日下单数,下单金额及下单用户数
在这里插入图片描述

支付信息统计

每日支付金额、支付人数、支付商品数、支付笔数以及下单到支付的平均时长(取自DWD)
运用了3张表
在这里插入图片描述

复购率

需求各一级品类下月品牌复购率
在这里插入图片描述

各个阶层的代码

insert into table ads_continuity_wk_count
select
   '$do_date',
   concat(date_add(next_day('$do_date','MO'),-7*3),'_',date_add(next_day('$do_date','MO'),-1)),
   count(*)
from
(select
   mid_id
from
(
select
   mid_id
from dws_uv_detail_daycount
where dt>=date_add(next_day('$do_date','MO'),-7)
and dt<=date_add(next_day('$do_date','MO'),-1)
group by mid_id
  union all
select
   mid_id
from dws_uv_detail_daycount
where dt>=date_add(next_day('$do_date','MO'),-7*2)
and dt<=date_add(next_day('$do_date','MO'),-1-7)
group by mid_id
  union all
select
   mid_id
from dws_uv_detail_daycount
where dt>=date_add(next_day('$do_date','MO'),-7*3)
and dt<=date_add(next_day('$do_date','MO'),-1-7*2)
group by mid_id
)t1
group by mid_id
having count(*)=3)t2;


insert into table ads_continuity_uv_count
select 
   '$do_date',
   concat(date_add('$do_date',-6),'_','$do_date'),
   count(*)
from
(select
  mid_id
from
(select
   mid_id,
   datediff
from 
   (select 
  mid_id,
  (lead-dt) datediff 
from 
  (select 
  mid_id,
  dt,
  lead(dt,2,'1970-01-01') over(partition by mid_id order by dt)  lead
from dws_uv_detail_daycount)t1)t2
where datediff=2)t3
group by mid_id)t4;

insert into table ads_user_topic
select 
   '$do_date',
   sum(if(login_date_last='$do_date',1,0)),
   sum(if(login_date_first='$do_date',1,0)),
   sum(if(payment_date_first='$do_date',1,0)),
   sum(if(payment_count>0,1,0)),
   count(*),
   sum(if(login_date_last='$do_date',1,0))/count(*),
   sum(if(payment_count>0,1,0))/count(*),
   sum(if(login_date_first='$do_date',1,0))/
sum(if(login_date_last='$do_date',1,0))
from dwt_user_topic; 

insert into table ads_user_action_convert_day
select
   uv.dt,
   uv.day_count,
   cart_count,
   cart_count/uv.day_count,
   order_count,
   order_count/cart_count,
   payment_count,
   payment_count/order_count
from
(
select
   '$do_date' dt,
   sum(if(cart_count>0,1,0)) cart_count,
   sum(if(order_count>0,1,0)) order_count,
   sum(if(payment_count>0,1,0)) payment_count
from dws_user_action_daycount
where dt='$do_date'
)ua
join ads_uv_count uv
on ua.dt=uv.dt;

insert into table ads_product_info
select
   '$do_date' dt,
   sku_num,
   spu_num
from
(
select
   '$do_date' dt,
   count(*) sku_num
from dwt_sku_topic
)tmp_sku_num 
join
(
select
   '$do_date' dt,
   count(*) spu_num
from
(
select
   spu_id
from
   dwt_sku_topic
group by spu_id
)tmp_spu_id
)tmp_spu_num
on tmp_spu_num.dt=tmp_sku_num.dt;


insert into table ads_product_sale_topN
select
   '$do_date',
   sku_id,
   payment_amount
from dws_sku_action_daycount
where dt='$do_date'
order by payment_amount desc;


insert into table ads_product_favor_topN
select 
   '$do_date',
   sku_id,
   favor_count 
from dws_sku_action_daycount
where dt='$do_date'
order by favor_count desc
limit 10;


insert into table ads_product_cart_topN
select
   '$do_date',
   sku_id,
   cart_num
from dws_sku_action_daycount
where dt='$do_date'
order by cart_num desc
limit 10;


insert into table ads_product_refund_topN
select
   '$do_date',
   sku_id,
   refund_last_30d_count/payment_last_30d_count*100 refund_ratio 
from dwt_sku_topic 
order by refund_ratio desc 
limit 10;


insert into table ads_appraise_bad_topN
select
   '$do_date',
   sku_id,
   appraise_bad_count/(appraise_good_count+appraise_mid_count+
appraise_bad_count+appraise_default_count) appraise_bad_ratio 
from dws_sku_action_daycount
where dt='$do_date'
order by appraise_bad_ratio desc
limit 10;


insert into table ads_order_daycount
select
   '$do_date',
   sum(order_count),
   sum(order_amount),
   sum(if(order_count>0,1,0))
from  dws_user_action_daycount
where dt='$do_date';



insert into table ads_payment_daycount
select
   tmp_payment.dt, 
   tmp_payment.payment_count,
   tmp_payment.payment_amount,
   tmp_payment.payment_user_count,
   tmp_skucount.payment_sku_count,
   tmp_time.payment_avg_time
from
(
select
   '$do_date' dt,
   sum(payment_count) payment_count,
   sum(payment_amount) payment_amount,
   sum(if(payment_count>0,1,0)) payment_user_count 
from dws_user_action_daycount
where dt='$do_date'
)tmp_payment 
join
(
select
   '$do_date' dt,
   sum(if(payment_count>0,1,0)) payment_sku_count
from dws_sku_action_daycount
where dt='$do_date'
)tmp_skucount 
on tmp_payment.dt=tmp_skucount.dt
join
(
select
   '$do_date' dt,
   sum(unix_timestamp(payment_time)-
unix_timestamp(create_time))/count(*)/60 
payment_avg_time
from dwd_fact_order_info
where dt='$do_date' and payment_time is not null 
)tmp_time
on tmp_payment.dt=tmp_time.dt;



insert into table ads_payment_daycount
select
   tmp_payment.dt, 
   tmp_payment.payment_count,
   tmp_payment.payment_amount,
   tmp_payment.payment_user_count,
   tmp_skucount.payment_sku_count,
   tmp_time.payment_avg_time
from
(
select
   '$do_date' dt,
   sum(payment_count) payment_count,
   sum(payment_amount) payment_amount,
   sum(if(payment_count>0,1,0)) payment_user_count 
from dws_user_action_daycount
where dt='$do_date'
)tmp_payment 
join
(
select
   '$do_date' dt,
   sum(if(payment_count>0,1,0)) payment_sku_count
from dws_sku_action_daycount
where dt='$do_date'
)tmp_skucount 
on tmp_payment.dt=tmp_skucount.dt
join
(
select
   '$do_date' dt,
   sum(unix_timestamp(payment_time)-
unix_timestamp(create_time))/count(*)/60 
payment_avg_time
from dwd_fact_order_info
where dt='$do_date' and payment_time is not null 
)tmp_time
on tmp_payment.dt=tmp_time.dt;
  • 3
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
本教程为授权出品 一、课程简介数据仓库(Data Warehouse,可简写为DW或DWH),是面向分析的集成化数据环境,为企业决策制定过程,提供系统数据支持的战略集合,是国内外各大公司正在重点投入的战略级技术领域。 二、课程内容《大数据电商数仓项目实战》视频教程,从项目架构的搭建,到数据采集模块的设计、数仓架构的设计、实战需求实现、即席查询的实现,我们针对国内目前广泛使用的Apache原生框架和CDH版本框架进行了分别介绍,Apache原生框架介绍中涉及到的技术框架包括Flume、Kafka、Sqoop、MySql、HDFS、Hive、Tez、Spark、Presto、Druid等,CDH版本框架讲解包括CM的安装部署、Hadoop、Zookeeper、Hive、Flume、Kafka、Oozie、Impala、HUE、Kudu、Spark的安装配置,透彻了解不同版本框架的区别联系,将大数据全生态系统前沿技术一网打尽。在过程中对大数据生态体系进行了系统的讲解,对实际企业数仓项目中可能涉及到的技术点都进行了深入的讲解和探讨。同时穿插了大量数仓基础理论知识,让你在掌握实战经验的同时能够打下坚实的理论基础。 三、课程目标本课程以国内电商巨头实际业务应用场景为依托,对电商数仓的常见实战指标以及难点实战指标进行了详尽讲解,具体指标包括:每日、周、月活跃设备明细,留存用户比例,沉默用户、回流用户、流失用户统计,最近连续3周活跃用户统计,最近7天内连续3天活跃用户统计,GMV成交总额分析,转化率及漏斗分析,品牌复购率分析、订单表拉链表的设计等,让学生拥有更直观全面的实战经验。通过对本课程的学习,对数仓项目可以建立起清晰明确的概念,系统全面的掌握各项数仓项目技术,轻松应对各种数仓难题。 四、课程亮点本课程结合国内多家企业实际项目经验,特别加入了项目架构模块,从集群规模的确定到框架版本选型以及服务器选型,手把手教你从零开始搭建大数据集群。并且总结大量项目实战中会遇到的问题,针对各个技术框架,均有调优实战经验,具体包括:常用Linux运维命令、Hadoop集群调优、Flume组件选型及性能优化、Kafka集群规模确认及关键参数调优。通过这部分学习,助学生迅速成长,获取前沿技术经验,从容解决实战问题。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Knight_AL

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值