[数仓]四、离线数仓(Hive数仓系统-续)

 第8章 数仓搭建-DWT

8.1 访客主题

1)建表语句

DROP TABLE IF EXISTS dwt_visitor_topic;
CREATE EXTERNAL TABLE dwt_visitor_topic
(`mid_id` STRING COMMENT '设备id',`brand` STRING COMMENT '手机品牌',`model` STRING COMMENT '手机型号',`channel` ARRAY<STRING> COMMENT '渠道',`os` ARRAY<STRING> COMMENT '操作系统',`area_code` ARRAY<STRING> COMMENT '地区ID',`version_code` ARRAY<STRING> COMMENT '应用版本',`visit_date_first` STRING  COMMENT '首次访问时间',`visit_date_last` STRING  COMMENT '末次访问时间',`visit_last_1d_count` BIGINT COMMENT '最近1日访问次数',`visit_last_1d_day_count` BIGINT COMMENT '最近1日访问天数',`visit_last_7d_count` BIGINT COMMENT '最近7日访问次数',`visit_last_7d_day_count` BIGINT COMMENT '最近7日访问天数',`visit_last_30d_count` BIGINT COMMENT '最近30日访问次数',`visit_last_30d_day_count` BIGINT COMMENT '最近30日访问天数',`visit_count` BIGINT COMMENT '累积访问次数',`visit_day_count` BIGINT COMMENT '累积访问天数'
) COMMENT '设备主题宽表'
PARTITIONED BY (`dt` STRING)
STORED AS PARQUET
LOCATION '/warehouse/gmall/dwt/dwt_visitor_topic'
TBLPROPERTIES ("parquet.compression"="lzo");

2)数据装载

insert overwrite table dwt_visitor_topic partition(dt='2020-06-14')
selectnvl(1d_ago.mid_id,old.mid_id),nvl(1d_ago.brand,old.brand),nvl(1d_ago.model,old.model),nvl(1d_ago.channel,old.channel),nvl(1d_ago.os,old.os),nvl(1d_ago.area_code,old.area_code),nvl(1d_ago.version_code,old.version_code),case when old.mid_id is null and 1d_ago.is_new=1 then '2020-06-14'when old.mid_id is null and 1d_ago.is_new=0 then '2020-06-13'--无法获取准确的首次登录日期,给定一个数仓搭建日之前的日期else old.visit_date_first end,if(1d_ago.mid_id is not null,'2020-06-14',old.visit_date_last),nvl(1d_ago.visit_count,0),if(1d_ago.mid_id is null,0,1),nvl(old.visit_last_7d_count,0)+nvl(1d_ago.visit_count,0)- nvl(7d_ago.visit_count,0),nvl(old.visit_last_7d_day_count,0)+if(1d_ago.mid_id is null,0,1)- if(7d_ago.mid_id is null,0,1),nvl(old.visit_last_30d_count,0)+nvl(1d_ago.visit_count,0)- nvl(30d_ago.visit_count,0),nvl(old.visit_last_30d_day_count,0)+if(1d_ago.mid_id is null,0,1)- if(30d_ago.mid_id is null,0,1),nvl(old.visit_count,0)+nvl(1d_ago.visit_count,0),nvl(old.visit_day_count,0)+if(1d_ago.mid_id is null,0,1)
from
(selectmid_id,brand,model,channel,os,area_code,version_code,visit_date_first,visit_date_last,visit_last_1d_count,visit_last_1d_day_count,visit_last_7d_count,visit_last_7d_day_count,visit_last_30d_count,visit_last_30d_day_count,visit_count,visit_day_countfrom dwt_visitor_topicwhere dt=date_add('2020-06-14',-1)
)old
full outer join
(selectmid_id,brand,model,is_new,channel,os,area_code,version_code,visit_countfrom dws_visitor_action_daycountwhere dt='2020-06-14'
)1d_ago
on old.mid_id=1d_ago.mid_id
left join
(selectmid_id,brand,model,is_new,channel,os,area_code,version_code,visit_countfrom dws_visitor_action_daycountwhere dt=date_add('2020-06-14',-7)
)7d_ago
on old.mid_id=7d_ago.mid_id
left join
(selectmid_id,brand,model,is_new,channel,os,area_code,version_code,visit_countfrom dws_visitor_action_daycountwhere dt=date_add('2020-06-14',-30)
)30d_ago
on old.mid_id=30d_ago.mid_id;

3)查询加载结果

8.2 用户主题

1)建表语句

DROP TABLE IF EXISTS dwt_user_topic;
CREATE EXTERNAL TABLE dwt_user_topic
(`user_id` STRING  COMMENT '用户id',`login_date_first` STRING COMMENT '首次活跃日期',`login_date_last` STRING COMMENT '末次活跃日期',`login_date_1d_count` STRING COMMENT '最近1日登录次数',`login_last_1d_day_count` BIGINT COMMENT '最近1日登录天数',`login_last_7d_count` BIGINT COMMENT '最近7日登录次数',`login_last_7d_day_count` BIGINT COMMENT '最近7日登录天数',`login_last_30d_count` BIGINT COMMENT '最近30日登录次数',`login_last_30d_day_count` BIGINT COMMENT '最近30日登录天数',`login_count` BIGINT COMMENT '累积登录次数',`login_day_count` BIGINT COMMENT '累积登录天数',`order_date_first` STRING COMMENT '首次下单时间',`order_date_last` STRING COMMENT '末次下单时间',`order_last_1d_count` BIGINT COMMENT '最近1日下单次数',`order_activity_last_1d_count` BIGINT COMMENT '最近1日订单参与活动次数',`order_activity_reduce_last_1d_amount` DECIMAL(16,2) COMMENT '最近1日订单减免金额(活动)',`order_coupon_last_1d_count` BIGINT COMMENT '最近1日下单用券次数',`order_coupon_reduce_last_1d_amount` DECIMAL(16,2) COMMENT '最近1日订单减免金额(优惠券)',`order_last_1d_original_amount` DECIMAL(16,2) COMMENT '最近1日原始下单金额',`order_last_1d_final_amount` DECIMAL(16,2) COMMENT '最近1日最终下单金额',`order_last_7d_count` BIGINT COMMENT '最近7日下单次数',`order_activity_last_7d_count` BIGINT COMMENT '最近7日订单参与活动次数',`order_activity_reduce_last_7d_amount` DECIMAL(16,2) COMMENT '最近7日订单减免金额(活动)',`order_coupon_last_7d_count` BIGINT COMMENT '最近7日下单用券次数',`order_coupon_reduce_last_7d_amount` DECIMAL(16,2) COMMENT '最近7日订单减免金额(优惠券)',`order_last_7d_original_amount` DECIMAL(16,2) COMMENT '最近7日原始下单金额',`order_last_7d_final_amount` DECIMAL(16,2) COMMENT '最近7日最终下单金额',`order_last_30d_count` BIGINT COMMENT '最近30日下单次数',`order_activity_last_30d_count` BIGINT COMMENT '最近30日订单参与活动次数',`order_activity_reduce_last_30d_amount` DECIMAL(16,2) COMMENT '最近30日订单减免金额(活动)',`order_coupon_last_30d_count` BIGINT COMMENT '最近30日下单用券次数',`order_coupon_reduce_last_30d_amount` DECIMAL(16,2) COMMENT '最近30日订单减免金额(优惠券)',`order_last_30d_original_amount` DECIMAL(16,2) COMMENT '最近30日原始下单金额',`order_last_30d_final_amount` DECIMAL(16,2) COMMENT '最近30日最终下单金额',`order_count` BIGINT COMMENT '累积下单次数',`order_activity_count` BIGINT COMMENT '累积订单参与活动次数',`order_activity_reduce_amount` DECIMAL(16,2) COMMENT '累积订单减免金额(活动)',`order_coupon_count` BIGINT COMMENT '累积下单用券次数',`order_coupon_reduce_amount` DECIMAL(16,2) COMMENT '累积订单减免金额(优惠券)',`order_original_amount` DECIMAL(16,2) COMMENT '累积原始下单金额',`order_final_amount` DECIMAL(16,2) COMMENT '累积最终下单金额',`payment_date_first` STRING COMMENT '首次支付时间',`payment_date_last` STRING COMMENT '末次支付时间',`payment_last_1d_count` BIGINT COMMENT '最近1日支付次数',`payment_last_1d_amount` DECIMAL(16,2) COMMENT '最近1日支付金额',`payment_last_7d_count` BIGINT COMMENT '最近7日支付次数',`payment_last_7d_amount` DECIMAL(16,2) COMMENT '最近7日支付金额',`payment_last_30d_count` BIGINT COMMENT '最近30日支付次数',`payment_last_30d_amount` DECIMAL(16,2) COMMENT '最近30日支付金额',`payment_count` BIGINT COMMENT '累积支付次数',`payment_amount` DECIMAL(16,2) COMMENT '累积支付金额',`refund_order_last_1d_count` BIGINT COMMENT '最近1日退单次数',`refund_order_last_1d_num` BIGINT COMMENT '最近1日退单件数',`refund_order_last_1d_amount` DECIMAL(16,2) COMMENT '最近1日退单金额',`refund_order_last_7d_count` BIGINT COMMENT '最近7日退单次数',`refund_order_last_7d_num` BIGINT COMMENT '最近7日退单件数',`refund_order_last_7d_amount` DECIMAL(16,2) COMMENT '最近7日退单金额',`refund_order_last_30d_count` BIGINT COMMENT '最近30日退单次数',`refund_order_last_30d_num` BIGINT COMMENT '最近30日退单件数',`refund_order_last_30d_amount` DECIMAL(16,2) COMMENT '最近30日退单金额',`refund_order_count` BIGINT COMMENT '累积退单次数',`refund_order_num` BIGINT COMMENT '累积退单件数',`refund_order_amount` DECIMAL(16,2) COMMENT '累积退单金额',`refund_payment_last_1d_count` BIGINT COMMENT '最近1日退款次数',`refund_payment_last_1d_num` BIGINT COMMENT '最近1日退款件数',`refund_payment_last_1d_amount` DECIMAL(16,2) COMMENT '最近1日退款金额',`refund_payment_last_7d_count` BIGINT COMMENT '最近7日退款次数',`refund_payment_last_7d_num` BIGINT COMMENT '最近7日退款件数',`refund_payment_last_7d_amount` DECIMAL(16,2) COMMENT '最近7日退款金额',`refund_payment_last_30d_count` BIGINT COMMENT '最近30日退款次数',`refund_payment_last_30d_num` BIGINT COMMENT '最近30日退款件数',`refund_payment_last_30d_amount` DECIMAL(16,2) COMMENT '最近30日退款金额',`refund_payment_count` BIGINT COMMENT '累积退款次数',`refund_payment_num` BIGINT COMMENT '累积退款件数',`refund_payment_amount` DECIMAL(16,2) COMMENT '累积退款金额',`cart_last_1d_count` BIGINT COMMENT '最近1日加入购物车次数',`cart_last_7d_count` BIGINT COMMENT '最近7日加入购物车次数',`cart_last_30d_count` BIGINT COMMENT '最近30日加入购物车次数',`cart_count` BIGINT COMMENT '累积加入购物车次数',`favor_last_1d_count` BIGINT COMMENT '最近1日收藏次数',`favor_last_7d_count` BIGINT COMMENT '最近7日收藏次数',`favor_last_30d_count` BIGINT COMMENT '最近30日收藏次数',`favor_count` BIGINT COMMENT '累积收藏次数',`coupon_last_1d_get_count` BIGINT COMMENT '最近1日领券次数',`coupon_last_1d_using_count` BIGINT COMMENT '最近1日用券(下单)次数',`coupon_last_1d_used_count` BIGINT COMMENT '最近1日用券(支付)次数',`coupon_last_7d_get_count` BIGINT COMMENT '最近7日领券次数',`coupon_last_7d_using_count` BIGINT COMMENT '最近7日用券(下单)次数',`coupon_last_7d_used_count` BIGINT COMMENT '最近7日用券(支付)次数',`coupon_last_30d_get_count` BIGINT COMMENT '最近30日领券次数',`coupon_last_30d_using_count` BIGINT COMMENT '最近30日用券(下单)次数',`coupon_last_30d_used_count` BIGINT COMMENT '最近30日用券(支付)次数',`coupon_get_count` BIGINT COMMENT '累积领券次数',`coupon_using_count` BIGINT COMMENT '累积用券(下单)次数',`coupon_used_count` BIGINT COMMENT '累积用券(支付)次数',`appraise_last_1d_good_count` BIGINT COMMENT '最近1日好评次数',`appraise_last_1d_mid_count` BIGINT COMMENT '最近1日中评次数',`appraise_last_1d_bad_count` BIGINT COMMENT '最近1日差评次数',`appraise_last_1d_default_count` BIGINT COMMENT '最近1日默认评价次数',`appraise_last_7d_good_count` BIGINT COMMENT '最近7日好评次数',`appraise_last_7d_mid_count` BIGINT COMMENT '最近7日中评次数',`appraise_last_7d_bad_count` BIGINT COMMENT '最近7日差评次数',`appraise_last_7d_default_count` BIGINT COMMENT '最近7日默认评价次数',`appraise_last_30d_good_count` BIGINT COMMENT '最近30日好评次数',`appraise_last_30d_mid_count` BIGINT COMMENT '最近30日中评次数',`appraise_last_30d_bad_count` BIGINT COMMENT '最近30日差评次数',`appraise_last_30d_default_count` BIGINT COMMENT '最近30日默认评价次数',`appraise_good_count` BIGINT COMMENT '累积好评次数',`appraise_mid_count` BIGINT COMMENT '累积中评次数',`appraise_bad_count` BIGINT COMMENT '累积差评次数',`appraise_default_count` BIGINT COMMENT '累积默认评价次数'
)COMMENT '会员主题宽表'
PARTITIONED BY (`dt` STRING)
STORED AS PARQUET
LOCATION '/warehouse/gmall/dwt/dwt_user_topic/'
TBLPROPERTIES ("parquet.compression"="lzo");

2)数据装载

(1)首日装载

insert overwrite table dwt_user_topic partition(dt='2020-06-14')
selectid,login_date_first,--以用户的创建日期作为首次登录日期nvl(login_date_last,date_add('2020-06-14',-1)),--若有历史登录记录,则根据历史记录获取末次登录日期,否则统一指定一个日期nvl(login_last_1d_count,0),nvl(login_last_1d_day_count,0),nvl(login_last_7d_count,0),nvl(login_last_7d_day_count,0),nvl(login_last_30d_count,0),nvl(login_last_30d_day_count,0),nvl(login_count,0),nvl(login_day_count,0),order_date_first,order_date_last,nvl(order_last_1d_count,0),nvl(order_activity_last_1d_count,0),nvl(order_activity_reduce_last_1d_amount,0),nvl(order_coupon_last_1d_count,0),nvl(order_coupon_reduce_last_1d_amount,0),nvl(order_last_1d_original_amount,0),nvl(order_last_1d_final_amount,0),nvl(order_last_7d_count,0),nvl(order_activity_last_7d_count,0),nvl(order_activity_reduce_last_7d_amount,0),nvl(order_coupon_last_7d_count,0),nvl(order_coupon_reduce_last_7d_amount,0),nvl(order_last_7d_original_amount,0),nvl(order_last_7d_final_amount,0),nvl(order_last_30d_count,0),nvl(order_activity_last_30d_count,0),nvl(order_activity_reduce_last_30d_amount,0),nvl(order_coupon_last_30d_count,0),nvl(order_coupon_reduce_last_30d_amount,0),nvl(order_last_30d_original_amount,0),nvl(order_last_30d_final_amount,0),nvl(order_count,0),nvl(order_activity_count,0),nvl(order_activity_reduce_amount,0),nvl(order_coupon_count,0),nvl(order_coupon_reduce_amount,0),nvl(order_original_amount,0),nvl(order_final_amount,0),payment_date_first,payment_date_last,nvl(payment_last_1d_count,0),nvl(payment_last_1d_amount,0),nvl(payment_last_7d_count,0),nvl(payment_last_7d_amount,0),nvl(payment_last_30d_count,0),nvl(payment_last_30d_amount,0),nvl(payment_count,0),nvl(payment_amount,0),nvl(refund_order_last_1d_count,0),nvl(refund_order_last_1d_num,0),nvl(refund_order_last_1d_amount,0),nvl(refund_order_last_7d_count,0),nvl(refund_order_last_7d_num,0),nvl(refund_order_last_7d_amount,0),nvl(refund_order_last_30d_count,0),nvl(refund_order_last_30d_num,0),nvl(refund_order_last_30d_amount,0),nvl(refund_order_count,0),nvl(refund_order_num,0),nvl(refund_order_amount,0),nvl(refund_payment_last_1d_count,0),nvl(refund_payment_last_1d_num,0),nvl(refund_payment_last_1d_amount,0),nvl(refund_payment_last_7d_count,0),nvl(refund_payment_last_7d_num,0),nvl(refund_payment_last_7d_amount,0),nvl(refund_payment_last_30d_count,0),nvl(refund_payment_last_30d_num,0),nvl(refund_payment_last_30d_amount,0),nvl(refund_payment_count,0),nvl(refund_payment_num,0),nvl(refund_payment_amount,0),nvl(cart_last_1d_count,0),nvl(cart_last_7d_count,0),nvl(cart_last_30d_count,0),nvl(cart_count,0),nvl(favor_last_1d_count,0),nvl(favor_last_7d_count,0),nvl(favor_last_30d_count,0),nvl(favor_count,0),nvl(coupon_last_1d_get_count,0),nvl(coupon_last_1d_using_count,0),nvl(coupon_last_1d_used_count,0),nvl(coupon_last_7d_get_count,0),nvl(coupon_last_7d_using_count,0),nvl(coupon_last_7d_used_count,0),nvl(coupon_last_30d_get_count,0),nvl(coupon_last_30d_using_count,0),nvl(coupon_last_30d_used_count,0),nvl(coupon_get_count,0),nvl(coupon_using_count,0),nvl(coupon_used_count,0),nvl(appraise_last_1d_good_count,0),nvl(appraise_last_1d_mid_count,0),nvl(appraise_last_1d_bad_count,0),nvl(appraise_last_1d_default_count,0),nvl(appraise_last_7d_good_count,0),nvl(appraise_last_7d_mid_count,0),nvl(appraise_last_7d_bad_count,0),nvl(appraise_last_7d_default_count,0),nvl(appraise_last_30d_good_count,0),nvl(appraise_last_30d_mid_count,0),nvl(appraise_last_30d_bad_count,0),nvl(appraise_last_30d_default_count,0),nvl(appraise_good_count,0),nvl(appraise_mid_count,0),nvl(appraise_bad_count,0),nvl(appraise_default_count,0)
from
(selectid,date_format(create_time,'yyyy-MM-dd') login_date_firstfrom dim_user_infowhere dt='9999-99-99'
)t1
left join
(selectuser_id user_id,max(dt) login_date_last,sum(if(dt='2020-06-14',login_count,0)) login_last_1d_count,sum(if(dt='2020-06-14' and login_count>0,1,0)) login_last_1d_day_count,sum(if(dt>=date_add('2020-06-14',-6),login_count,0)) login_last_7d_count,sum(if(dt>=date_add('2020-06-14',-6) and login_count>0,1,0)) login_last_7d_day_count,sum(if(dt>=date_add('2020-06-14',-29),login_count,0)) login_last_30d_count,sum(if(dt>=date_add('2020-06-14',-29) and login_count>0,1,0)) login_last_30d_day_count,sum(login_count) login_count,sum(if(login_count>0,1,0)) login_day_count,min(if(order_count>0,dt,null)) order_date_first,max(if(order_count>0,dt,null)) order_date_last,sum(if(dt='2020-06-14',order_count,0)) order_last_1d_count,sum(if(dt='2020-06-14',order_activity_count,0)) order_activity_last_1d_count,sum(if(dt='2020-06-14',order_activity_reduce_amount,0)) order_activity_reduce_last_1d_amount,sum(if(dt='2020-06-14',order_coupon_count,0)) order_coupon_last_1d_count,sum(if(dt='2020-06-14',order_coupon_reduce_amount,0)) order_coupon_reduce_last_1d_amount,sum(if(dt='2020-06-14',order_original_amount,0)) order_last_1d_original_amount,sum(if(dt='2020-06-14',order_final_amount,0)) order_last_1d_final_amount,sum(if(dt>=date_add('2020-06-14',-6),order_count,0)) order_last_7d_count,sum(if(dt>=date_add('2020-06-14',-6),order_activity_count,0)) order_activity_last_7d_count,sum(if(dt>=date_add('2020-06-14',-6),order_activity_reduce_amount,0)) order_activity_reduce_last_7d_amount,sum(if(dt>=date_add('2020-06-14',-6),order_coupon_count,0)) order_coupon_last_7d_count,sum(if(dt>=date_add('2020-06-14',-6),order_coupon_reduce_amount,0)) order_coupon_reduce_last_7d_amount,sum(if(dt>=date_add('2020-06-14',-6),order_original_amount,0)) order_last_7d_original_amount,sum(if(dt>=date_add('2020-06-14',-6),order_final_amount,0)) order_last_7d_final_amount,sum(if(dt>=date_add('2020-06-14',-29),order_count,0)) order_last_30d_count,sum(if(dt>=date_add('2020-06-14',-29),order_activity_count,0)) order_activity_last_30d_count,sum(if(dt>=date_add('2020-06-14',-29),order_activity_reduce_amount,0)) order_activity_reduce_last_30d_amount,sum(if(dt>=date_add('2020-06-14',-29),order_coupon_count,0)) order_coupon_last_30d_count,sum(if(dt>=date_add('2020-06-14',-29),order_coupon_reduce_amount,0)) order_coupon_reduce_last_30d_amount,sum(if(dt>=date_add('2020-06-14',-29),order_original_amount,0)) order_last_30d_original_amount,sum(if(dt>=date_add('2020-06-14',-29),order_final_amount,0)) order_last_30d_final_amount,sum(order_count) order_count,sum(order_activity_count) order_activity_count,sum(order_activity_reduce_amount) order_activity_reduce_amount,sum(order_coupon_count) order_coupon_count,sum(order_coupon_reduce_amount) order_coupon_reduce_amount,sum(order_original_amount) order_original_amount,sum(order_final_amount) order_final_amount,min(if(payment_count>0,dt,null)) payment_date_first,max(if(payment_count>0,dt,null)) payment_date_last,sum(if(dt='2020-06-14',payment_count,0)) payment_last_1d_count,sum(if(dt='2020-06-14',payment_amount,0)) payment_last_1d_amount,sum(if(dt>=date_add('2020-06-14',-6),payment_count,0)) payment_last_7d_count,sum(if(dt>=date_add('2020-06-14',-6),payment_amount,0)) payment_last_7d_amount,sum(if(dt>=date_add('2020-06-14',-29),payment_count,0)) payment_last_30d_count,sum(if(dt>=date_add('2020-06-14',-29),payment_amount,0)) payment_last_30d_amount,sum(payment_count) payment_count,sum(payment_amount) payment_amount,sum(if(dt='2020-06-14',refund_order_count,0)) refund_order_last_1d_count,sum(if(dt='2020-06-14',refund_order_num,0)) refund_order_last_1d_num,sum(if(dt='2020-06-14',refund_order_amount,0)) refund_order_last_1d_amount,sum(if(dt>=date_add('2020-06-14',-6),refund_order_count,0)) refund_order_last_7d_count,sum(if(dt>=date_add('2020-06-14',-6),refund_order_num,0)) refund_order_last_7d_num,sum(if(dt>=date_add('2020-06-14',-6),refund_order_amount,0)) refund_order_last_7d_amount,sum(if(dt>=date_add('2020-06-14',-29),refund_order_count,0)) refund_order_last_30d_count,sum(if(dt>=date_add('2020-06-14',-29),refund_order_num,0)) refund_order_last_30d_num,sum(if(dt>=date_add('2020-06-14',-29),refund_order_amount,0)) refund_order_last_30d_amount,sum(refund_order_count) refund_order_count,sum(refund_order_num) refund_order_num,sum(refund_order_amount) refund_order_amount,sum(if(dt='2020-06-14',refund_payment_count,0)) refund_payment_last_1d_count,sum(if(dt='2020-06-14',refund_payment_num,0)) refund_payment_last_1d_num,sum(if(dt='2020-06-14',refund_payment_amount,0)) refund_payment_last_1d_amount,sum(if(dt>=date_add('2020-06-14',-6),refund_payment_count,0)) refund_payment_last_7d_count,sum(if(dt>=date_add('2020-06-14',-6),refund_payment_num,0)) refund_payment_last_7d_num,sum(if(dt>=date_add('2020-06-14',-6),refund_payment_amount,0)) refund_payment_last_7d_amount,sum(if(dt>=date_add('2020-06-14',-29),refund_payment_count,0)) refund_payment_last_30d_count,sum(if(dt>=date_add('2020-06-14',-29),refund_payment_num,0)) refund_payment_last_30d_num,sum(if(dt>=date_add('2020-06-14',-29),refund_payment_amount,0)) refund_payment_last_30d_amount,sum(refund_payment_count) refund_payment_count,sum(refund_payment_num) refund_payment_num,sum(refund_payment_amount) refund_payment_amount,sum(if(dt='2020-06-14',cart_count,0)) cart_last_1d_count,sum(if(dt>=date_add('2020-06-14',-6),cart_count,0)) cart_last_7d_count,sum(if(dt>=date_add('2020-06-14',-29),cart_count,0)) cart_last_30d_count,sum(cart_count) cart_count,sum(if(dt='2020-06-14',favor_count,0)) favor_last_1d_count,sum(if(dt>=date_add('2020-06-14',-6),favor_count,0)) favor_last_7d_count,sum(if(dt>=date_add('2020-06-14',-29),favor_count,0)) favor_last_30d_count,sum(favor_count) favor_count,sum(if(dt='2020-06-14',coupon_get_count,0)) coupon_last_1d_get_count,sum(if(dt='2020-06-14',coupon_using_count,0)) coupon_last_1d_using_count,sum(if(dt='2020-06-14',coupon_used_count,0)) coupon_last_1d_used_count,sum(if(dt>=date_add('2020-06-14',-6),coupon_get_count,0)) coupon_last_7d_get_count,sum(if(dt>=date_add('2020-06-14',-6),coupon_using_count,0)) coupon_last_7d_using_count,sum(if(dt>=date_add('2020-06-14',-6),coupon_used_count,0)) coupon_last_7d_used_count,sum(if(dt>=date_add('2020-06-14',-29),coupon_get_count,0)) coupon_last_30d_get_count,sum(if(dt>=date_add('2020-06-14',-29),coupon_using_count,0)) coupon_last_30d_using_count,sum(if(dt>=date_add('2020-06-14',-29),coupon_used_count,0)) coupon_last_30d_used_count,sum(coupon_get_count) coupon_get_count,sum(coupon_using_count) coupon_using_count,sum(coupon_used_count) coupon_used_count,sum(if(dt='2020-06-14',appraise_good_count,0)) appraise_last_1d_good_count,sum(if(dt='2020-06-14',appraise_mid_count,0)) appraise_last_1d_mid_count,sum(if(dt='2020-06-14',appraise_bad_count,0)) appraise_last_1d_bad_count,sum(if(dt='2020-06-14',appraise_default_count,0)) appraise_last_1d_default_count,sum(if(dt>=date_add('2020-06-14',-6),appraise_good_count,0)) appraise_last_7d_good_count,sum(if(dt>=date_add('2020-06-14',-6),appraise_mid_count,0)) appraise_last_7d_mid_count,sum(if(dt>=date_add('2020-06-14',-6),appraise_bad_count,0)) appraise_last_7d_bad_count,sum(if(dt>=date_add('2020-06-14',-6),appraise_default_count,0)) appraise_last_7d_default_count,sum(if(dt>=date_add('2020-06-14',-29),appraise_good_count,0)) appraise_last_30d_good_count,sum(if(dt>=date_add('2020-06-14',-29),appraise_mid_count,0)) appraise_last_30d_mid_count,sum(if(dt>=date_add('2020-06-14',-29),appraise_bad_count,0)) appraise_last_30d_bad_count,sum(if(dt>=date_add('2020-06-14',-29),appraise_default_count,0)) appraise_last_30d_default_count,sum(appraise_good_count) appraise_good_count,sum(appraise_mid_count) appraise_mid_count,sum(appraise_bad_count) appraise_bad_count,sum(appraise_default_count) appraise_default_countfrom dws_user_action_daycountgroup by user_id
)t2
on t1.id=t2.user_id;

(2)每日装载

insert overwrite table dwt_user_topic partition(dt='2020-06-15')
selectnvl(1d_ago.user_id,old.user_id),nvl(old.login_date_first,'2020-06-15'),if(1d_ago.user_id is not null,'2020-06-15',old.login_date_last),nvl(1d_ago.login_count,0),if(1d_ago.user_id is not null,1,0),nvl(old.login_last_7d_count,0)+nvl(1d_ago.login_count,0)- nvl(7d_ago.login_count,0),nvl(old.login_last_7d_day_count,0)+if(1d_ago.user_id is null,0,1)- if(7d_ago.user_id is null,0,1),nvl(old.login_last_30d_count,0)+nvl(1d_ago.login_count,0)- nvl(30d_ago.login_count,0),nvl(old.login_last_30d_day_count,0)+if(1d_ago.user_id is null,0,1)- if(30d_ago.user_id is null,0,1),nvl(old.login_count,0)+nvl(1d_ago.login_count,0),nvl(old.login_day_count,0)+if(1d_ago.user_id is not null,1,0),if(old.order_date_first is null and 1d_ago.order_count>0, '2020-06-15', old.order_date_first),if(1d_ago.order_count>0,'2020-06-15',old.order_date_last),nvl(1d_ago.order_count,0),nvl(1d_ago.order_activity_count,0),nvl(1d_ago.order_activity_reduce_amount,0.0),nvl(1d_ago.order_coupon_count,0),nvl(1d_ago.order_coupon_reduce_amount,0.0),nvl(1d_ago.order_original_amount,0.0),nvl(1d_ago.order_final_amount,0.0),nvl(old.order_last_7d_count,0)+nvl(1d_ago.order_count,0)- nvl(7d_ago.order_count,0),nvl(old.order_activity_last_7d_count,0)+nvl(1d_ago.order_activity_count,0)- nvl(7d_ago.order_activity_count,0),nvl(old.order_activity_reduce_last_7d_amount,0.0)+nvl(1d_ago.order_activity_reduce_amount,0.0)- nvl(7d_ago.order_activity_reduce_amount,0.0),nvl(old.order_coupon_last_7d_count,0)+nvl(1d_ago.order_coupon_count,0)- nvl(7d_ago.order_coupon_count,0),nvl(old.order_coupon_reduce_last_7d_amount,0.0)+nvl(1d_ago.order_coupon_reduce_amount,0.0)- nvl(7d_ago.order_coupon_reduce_amount,0.0),nvl(old.order_last_7d_original_amount,0.0)+nvl(1d_ago.order_original_amount,0.0)- nvl(7d_ago.order_original_amount,0.0),nvl(old.order_last_7d_final_amount,0.0)+nvl(1d_ago.order_final_amount,0.0)- nvl(7d_ago.order_final_amount,0.0),nvl(old.order_last_30d_count,0)+nvl(1d_ago.order_count,0)- nvl(30d_ago.order_count,0),nvl(old.order_activity_last_30d_count,0)+nvl(1d_ago.order_activity_count,0)- nvl(30d_ago.order_activity_count,0),nvl(old.order_activity_reduce_last_30d_amount,0.0)+nvl(1d_ago.order_activity_reduce_amount,0.0)- nvl(30d_ago.order_activity_reduce_amount,0.0),nvl(old.order_coupon_last_30d_count,0)+nvl(1d_ago.order_coupon_count,0)- nvl(30d_ago.order_coupon_count,0),nvl(old.order_coupon_reduce_last_30d_amount,0.0)+nvl(1d_ago.order_coupon_reduce_amount,0.0)- nvl(30d_ago.order_coupon_reduce_amount,0.0),nvl(old.order_last_30d_original_amount,0.0)+nvl(1d_ago.order_original_amount,0.0)- nvl(30d_ago.order_original_amount,0.0),nvl(old.order_last_30d_final_amount,0.0)+nvl(1d_ago.order_final_amount,0.0)- nvl(30d_ago.order_final_amount,0.0),nvl(old.order_count,0)+nvl(1d_ago.order_count,0),nvl(old.order_activity_count,0)+nvl(1d_ago.order_activity_count,0),nvl(old.order_activity_reduce_amount,0.0)+nvl(1d_ago.order_activity_reduce_amount,0.0),nvl(old.order_coupon_count,0)+nvl(1d_ago.order_coupon_count,0),nvl(old.order_coupon_reduce_amount,0.0)+nvl(1d_ago.order_coupon_reduce_amount,0.0),nvl(old.order_original_amount,0.0)+nvl(1d_ago.order_original_amount,0.0),nvl(old.order_final_amount,0.0)+nvl(1d_ago.order_final_amount,0.0),if(old.payment_date_first is null and 1d_ago.payment_count>0, '2020-06-15', old.payment_date_first),if(1d_ago.payment_count>0,'2020-06-15',old.payment_date_last),nvl(1d_ago.payment_count,0),nvl(1d_ago.payment_amount,0.0),nvl(old.payment_last_7d_count,0)+nvl(1d_ago.payment_count,0)-nvl(7d_ago.payment_count,0),nvl(old.payment_last_7d_amount,0.0)+nvl(1d_ago.payment_amount,0.0)-nvl(7d_ago.payment_amount,0.0),nvl(old.payment_last_30d_count,0)+nvl(1d_ago.payment_count,0)-nvl(30d_ago.payment_count,0),nvl(old.payment_last_30d_amount,0.0)+nvl(1d_ago.payment_amount,0.0)- nvl(30d_ago.payment_amount,0.0),nvl(old.payment_count,0)+nvl(1d_ago.payment_count,0),nvl(old.payment_amount,0.0)+nvl(1d_ago.payment_amount,0.0),nvl(1d_ago.refund_order_count,0),nvl(1d_ago.refund_order_num,0),nvl(1d_ago.refund_order_amount,0.0),nvl(old.refund_order_last_7d_count,0)+nvl(1d_ago.refund_order_count,0)- nvl(7d_ago.refund_order_count,0),nvl(old.refund_order_last_7d_num,0)+nvl(1d_ago.refund_order_num, 0)- nvl(7d_ago.refund_order_num,0),nvl(old.refund_order_last_7d_amount,0.0)+ nvl(1d_ago.refund_order_amount,0.0)- nvl(7d_ago.refund_order_amount,0.0),nvl(old.refund_order_last_30d_count,0)+nvl(1d_ago.refund_order_count,0)- nvl(30d_ago.refund_order_count,0),nvl(old.refund_order_last_30d_num,0)+nvl(1d_ago.refund_order_num, 0)- nvl(30d_ago.refund_order_num,0),nvl(old.refund_order_last_30d_amount,0.0)+ nvl(1d_ago.refund_order_amount,0.0)- nvl(30d_ago.refund_order_amount,0.0),nvl(old.refund_order_count,0)+nvl(1d_ago.refund_order_count,0),nvl(old.refund_order_num,0)+nvl(1d_ago.refund_order_num,0),nvl(old.refund_order_amount,0.0)+ nvl(1d_ago.refund_order_amount,0.0),nvl(1d_ago.refund_payment_count,0),nvl(1d_ago.refund_payment_num,0),nvl(1d_ago.refund_payment_amount,0.0),nvl(old.refund_payment_last_7d_count,0)+nvl(1d_ago.refund_payment_count,0)-nvl(7d_ago.refund_payment_count,0),nvl(old.refund_payment_last_7d_num,0)+nvl(1d_ago.refund_payment_num,0)- nvl(7d_ago.refund_payment_num,0),nvl(old.refund_payment_last_7d_amount,0.0)+ nvl(1d_ago.refund_payment_amount,0.0)- nvl(7d_ago.refund_payment_amount,0.0),nvl(old.refund_payment_last_30d_count,0)+nvl(1d_ago.refund_payment_count,0)-nvl(30d_ago.refund_payment_count,0),nvl(old.refund_payment_last_30d_num,0)+nvl(1d_ago.refund_payment_num,0)- nvl(30d_ago.refund_payment_num,0),nvl(old.refund_payment_last_30d_amount,0.0)+ nvl(1d_ago.refund_payment_amount,0.0)- nvl(30d_ago.refund_payment_amount,0.0),nvl(old.refund_payment_count,0)+nvl(1d_ago.refund_payment_count,0),nvl(old.refund_payment_num,0)+nvl(1d_ago.refund_payment_num,0),nvl(old.refund_payment_amount,0.0)+nvl(1d_ago.refund_payment_amount,0.0),nvl(1d_ago.cart_count,0),nvl(old.cart_last_7d_count,0)+nvl(1d_ago.cart_count,0)-nvl(7d_ago.cart_count,0),nvl(old.cart_last_30d_count,0)+nvl(1d_ago.cart_count,0)-nvl(30d_ago.cart_count,0),nvl(old.cart_count,0)+nvl(1d_ago.cart_count,0),nvl(1d_ago.favor_count,0),nvl(old.favor_last_7d_count,0)+nvl(1d_ago.favor_count,0)- nvl(7d_ago.favor_count,0),nvl(old.favor_last_30d_count,0)+nvl(1d_ago.favor_count,0)- nvl(30d_ago.favor_count,0),nvl(old.favor_count,0)+nvl(1d_ago.favor_count,0),nvl(1d_ago.coupon_get_count,0),nvl(1d_ago.coupon_using_count,0),nvl(1d_ago.coupon_used_count,0),nvl(old.coupon_last_7d_get_count,0)+nvl(1d_ago.coupon_get_count,0)- nvl(7d_ago.coupon_get_count,0),nvl(old.coupon_last_7d_using_count,0)+nvl(1d_ago.coupon_using_count,0)- nvl(7d_ago.coupon_using_count,0),nvl(old.coupon_last_7d_used_count,0)+ nvl(1d_ago.coupon_used_count,0)- nvl(7d_ago.coupon_used_count,0),nvl(old.coupon_last_30d_get_count,0)+nvl(1d_ago.coupon_get_count,0)- nvl(30d_ago.coupon_get_count,0),nvl(old.coupon_last_30d_using_count,0)+nvl(1d_ago.coupon_using_count,0)- nvl(30d_ago.coupon_using_count,0),nvl(old.coupon_last_30d_used_count,0)+ nvl(1d_ago.coupon_used_count,0)- nvl(30d_ago.coupon_used_count,0),nvl(old.coupon_get_count,0)+nvl(1d_ago.coupon_get_count,0),nvl(old.coupon_using_count,0)+nvl(1d_ago.coupon_using_count,0),nvl(old.coupon_used_count,0)+nvl(1d_ago.coupon_used_count,0),nvl(1d_ago.appraise_good_count,0),nvl(1d_ago.appraise_mid_count,0),nvl(1d_ago.appraise_bad_count,0),nvl(1d_ago.appraise_default_count,0),nvl(old.appraise_last_7d_good_count,0)+nvl(1d_ago.appraise_good_count,0)- nvl(7d_ago.appraise_good_count,0),nvl(old.appraise_last_7d_mid_count,0)+nvl(1d_ago.appraise_mid_count,0)-nvl(7d_ago.appraise_mid_count,0),nvl(old.appraise_last_7d_bad_count,0)+nvl(1d_ago.appraise_bad_count,0)-nvl(7d_ago.appraise_bad_count,0),nvl(old.appraise_last_7d_default_count,0)+nvl(1d_ago.appraise_default_count,0)-nvl(7d_ago.appraise_default_count,0),nvl(old.appraise_last_30d_good_count,0)+nvl(1d_ago.appraise_good_count,0)- nvl(30d_ago.appraise_good_count,0),nvl(old.appraise_last_30d_mid_count,0)+nvl(1d_ago.appraise_mid_count,0)-nvl(30d_ago.appraise_mid_count,0),nvl(old.appraise_last_30d_bad_count,0)+nvl(1d_ago.appraise_bad_count,0)-nvl(30d_ago.appraise_bad_count,0),nvl(old.appraise_last_30d_default_count,0)+nvl(1d_ago.appraise_default_count,0)-nvl(30d_ago.appraise_default_count,0),nvl(old.appraise_good_count,0)+nvl(1d_ago.appraise_good_count,0),nvl(old.appraise_mid_count,0)+nvl(1d_ago.appraise_mid_count, 0),nvl(old.appraise_bad_count,0)+nvl(1d_ago.appraise_bad_count,0),nvl(old.appraise_default_count,0)+nvl(1d_ago.appraise_default_count,0)
from
(selectuser_id,login_date_first,login_date_last,login_date_1d_count,login_last_1d_day_count,login_last_7d_count,login_last_7d_day_count,login_last_30d_count,login_last_30d_day_count,login_count,login_day_count,order_date_first,order_date_last,order_last_1d_count,order_activity_last_1d_count,order_activity_reduce_last_1d_amount,order_coupon_last_1d_count,order_coupon_reduce_last_1d_amount,order_last_1d_original_amount,order_last_1d_final_amount,order_last_7d_count,order_activity_last_7d_count,order_activity_reduce_last_7d_amount,order_coupon_last_7d_count,order_coupon_reduce_last_7d_amount,order_last_7d_original_amount,order_last_7d_final_amount,order_last_30d_count,order_activity_last_30d_count,order_activity_reduce_last_30d_amount,order_coupon_last_30d_count,order_coupon_reduce_last_30d_amount,order_last_30d_original_amount,order_last_30d_final_amount,order_count,order_activity_count,order_activity_reduce_amount,order_coupon_count,order_coupon_reduce_amount,order_original_amount,order_final_amount,payment_date_first,payment_date_last,payment_last_1d_count,payment_last_1d_amount,payment_last_7d_count,payment_last_7d_amount,payment_last_30d_count,payment_last_30d_amount,payment_count,payment_amount,refund_order_last_1d_count,refund_order_last_1d_num,refund_order_last_1d_amount,refund_order_last_7d_count,refund_order_last_7d_num,refund_order_last_7d_amount,refund_order_last_30d_count,refund_order_last_30d_num,refund_order_last_30d_amount,refund_order_count,refund_order_num,refund_order_amount,refund_payment_last_1d_count,refund_payment_last_1d_num,refund_payment_last_1d_amount,refund_payment_last_7d_count,refund_payment_last_7d_num,refund_payment_last_7d_amount,refund_payment_last_30d_count,refund_payment_last_30d_num,refund_payment_last_30d_amount,refund_payment_count,refund_payment_num,refund_payment_amount,cart_last_1d_count,cart_last_7d_count,cart_last_30d_count,cart_count,favor_last_1d_count,favor_last_7d_count,favor_last_30d_count,favor_count,coupon_last_1d_get_count,coupon_last_1d_using_count,coupon_last_1d_used_count,coupon_last_7d_get_count,coupon_last_7d_using_count,coupon_last_7d_used_count,coupon_last_30d_get_count,coupon_last_30d_using_count,coupon_last_30d_used_count,coupon_get_count,coupon_using_count,coupon_used_count,appraise_last_1d_good_count,appraise_last_1d_mid_count,appraise_last_1d_bad_count,appraise_last_1d_default_count,appraise_last_7d_good_count,appraise_last_7d_mid_count,appraise_last_7d_bad_count,appraise_last_7d_default_count,appraise_last_30d_good_count,appraise_last_30d_mid_count,appraise_last_30d_bad_count,appraise_last_30d_default_count,appraise_good_count,appraise_mid_count,appraise_bad_count,appraise_default_countfrom dwt_user_topicwhere dt=date_add('2020-06-15',-1)
)old
full outer join
(selectuser_id,login_count,cart_count,favor_count,order_count,order_activity_count,order_activity_reduce_amount,order_coupon_count,order_coupon_reduce_amount,order_original_amount,order_final_amount,payment_count,payment_amount,refund_order_count,refund_order_num,refund_order_amount,refund_payment_count,refund_payment_num,refund_payment_amount,coupon_get_count,coupon_using_count,coupon_used_count,appraise_good_count,appraise_mid_count,appraise_bad_count,appraise_default_countfrom dws_user_action_daycountwhere dt='2020-06-15'
)1d_ago
on old.user_id=1d_ago.user_id
left join
(selectuser_id,login_count,cart_count,favor_count,order_count,order_activity_count,order_activity_reduce_amount,order_coupon_count,order_coupon_reduce_amount,order_original_amount,order_final_amount,payment_count,payment_amount,refund_order_count,refund_order_num,refund_order_amount,refund_payment_count,refund_payment_num,refund_payment_amount,coupon_get_count,coupon_using_count,coupon_used_count,appraise_good_count,appraise_mid_count,appraise_bad_count,appraise_default_countfrom dws_user_action_daycountwhere dt=date_add('2020-06-15',-7)
)7d_ago
on old.user_id=7d_ago.user_id
left join
(selectuser_id,login_count,cart_count,favor_count,order_count,order_activity_count,order_activity_reduce_amount,order_coupon_count,order_coupon_reduce_amount,order_original_amount,order_final_amount,payment_count,payment_amount,refund_order_count,refund_order_num,refund_order_amount,refund_payment_count,refund_payment_num,refund_payment_amount,coupon_get_count,coupon_using_count,coupon_used_count,appraise_good_count,appraise_mid_count,appraise_bad_count,appraise_default_countfrom dws_user_action_daycountwhere dt=date_add('2020-06-15',-30)
)30d_ago
on old.user_id=30d_ago.user_id;

3)查询加载结果

8.3 商品主题

1)建表语句

DROP TABLE IF EXISTS dwt_sku_topic;
CREATE EXTERNAL TABLE dwt_sku_topic
(`sku_id` STRING COMMENT 'sku_id',`order_last_1d_count` BIGINT COMMENT '最近1日被下单次数',`order_last_1d_num` BIGINT COMMENT '最近1日被下单件数',`order_activity_last_1d_count` BIGINT COMMENT '最近1日参与活动被下单次数',`order_coupon_last_1d_count` BIGINT COMMENT '最近1日使用优惠券被下单次数',`order_activity_reduce_last_1d_amount` DECIMAL(16,2) COMMENT '最近1日优惠金额(活动)',`order_coupon_reduce_last_1d_amount` DECIMAL(16,2) COMMENT '最近1日优惠金额(优惠券)',`order_last_1d_original_amount` DECIMAL(16,2) COMMENT '最近1日被下单原始金额',`order_last_1d_final_amount` DECIMAL(16,2) COMMENT '最近1日被下单最终金额',`order_last_7d_count` BIGINT COMMENT '最近7日被下单次数',`order_last_7d_num` BIGINT COMMENT '最近7日被下单件数',`order_activity_last_7d_count` BIGINT COMMENT '最近7日参与活动被下单次数',`order_coupon_last_7d_count` BIGINT COMMENT '最近7日使用优惠券被下单次数',`order_activity_reduce_last_7d_amount` DECIMAL(16,2) COMMENT '最近7日优惠金额(活动)',`order_coupon_reduce_last_7d_amount` DECIMAL(16,2) COMMENT '最近7日优惠金额(优惠券)',`order_last_7d_original_amount` DECIMAL(16,2) COMMENT '最近7日被下单原始金额',`order_last_7d_final_amount` DECIMAL(16,2) COMMENT '最近7日被下单最终金额',`order_last_30d_count` BIGINT COMMENT '最近30日被下单次数',`order_last_30d_num` BIGINT COMMENT '最近30日被下单件数',`order_activity_last_30d_count` BIGINT COMMENT '最近30日参与活动被下单次数',`order_coupon_last_30d_count` BIGINT COMMENT '最近30日使用优惠券被下单次数',`order_activity_reduce_last_30d_amount` DECIMAL(16,2) COMMENT '最近30日优惠金额(活动)',`order_coupon_reduce_last_30d_amount` DECIMAL(16,2) COMMENT '最近30日优惠金额(优惠券)',`order_last_30d_original_amount` DECIMAL(16,2) COMMENT '最近30日被下单原始金额',`order_last_30d_final_amount` DECIMAL(16,2) COMMENT '最近30日被下单最终金额',`order_count` BIGINT COMMENT '累积被下单次数',`order_num` BIGINT COMMENT '累积被下单件数',`order_activity_count` BIGINT COMMENT '累积参与活动被下单次数',`order_coupon_count` BIGINT COMMENT '累积使用优惠券被下单次数',`order_activity_reduce_amount` DECIMAL(16,2) COMMENT '累积优惠金额(活动)',`order_coupon_reduce_amount` DECIMAL(16,2) COMMENT '累积优惠金额(优惠券)',`order_original_amount` DECIMAL(16,2) COMMENT '累积被下单原始金额',`order_final_amount` DECIMAL(16,2) COMMENT '累积被下单最终金额',`payment_last_1d_count` BIGINT COMMENT '最近1日被支付次数',`payment_last_1d_num` BIGINT COMMENT '最近1日被支付件数',`payment_last_1d_amount` DECIMAL(16,2) COMMENT '最近1日被支付金额',`payment_last_7d_count` BIGINT COMMENT '最近7日被支付次数',`payment_last_7d_num` BIGINT COMMENT '最近7日被支付件数',`payment_last_7d_amount` DECIMAL(16,2) COMMENT '最近7日被支付金额',`payment_last_30d_count` BIGINT COMMENT '最近30日被支付次数',`payment_last_30d_num` BIGINT COMMENT '最近30日被支付件数',`payment_last_30d_amount` DECIMAL(16,2) COMMENT '最近30日被支付金额',`payment_count` BIGINT COMMENT '累积被支付次数',`payment_num` BIGINT COMMENT '累积被支付件数',`payment_amount` DECIMAL(16,2) COMMENT '累积被支付金额',`refund_order_last_1d_count` BIGINT COMMENT '最近1日退单次数',`refund_order_last_1d_num` BIGINT COMMENT '最近1日退单件数',`refund_order_last_1d_amount` DECIMAL(16,2) COMMENT '最近1日退单金额',`refund_order_last_7d_count` BIGINT COMMENT '最近7日退单次数',`refund_order_last_7d_num` BIGINT COMMENT '最近7日退单件数',`refund_order_last_7d_amount` DECIMAL(16,2) COMMENT '最近7日退单金额',`refund_order_last_30d_count` BIGINT COMMENT '最近30日退单次数',`refund_order_last_30d_num` BIGINT COMMENT '最近30日退单件数',`refund_order_last_30d_amount` DECIMAL(16,2) COMMENT '最近30日退单金额',`refund_order_count` BIGINT COMMENT '累积退单次数',`refund_order_num` BIGINT COMMENT '累积退单件数',`refund_order_amount` DECIMAL(16,2) COMMENT '累积退单金额',`refund_payment_last_1d_count` BIGINT COMMENT '最近1日退款次数',`refund_payment_last_1d_num` BIGINT COMMENT '最近1日退款件数',`refund_payment_last_1d_amount` DECIMAL(16,2) COMMENT '最近1日退款金额',`refund_payment_last_7d_count` BIGINT COMMENT '最近7日退款次数',`refund_payment_last_7d_num` BIGINT COMMENT '最近7日退款件数',`refund_payment_last_7d_amount` DECIMAL(16,2) COMMENT '最近7日退款金额',`refund_payment_last_30d_count` BIGINT COMMENT '最近30日退款次数',`refund_payment_last_30d_num` BIGINT COMMENT '最近30日退款件数',`refund_payment_last_30d_amount` DECIMAL(16,2) COMMENT '最近30日退款金额',`refund_payment_count` BIGINT COMMENT '累积退款次数',`refund_payment_num` BIGINT COMMENT '累积退款件数',`refund_payment_amount` DECIMAL(16,2) COMMENT '累积退款金额',`cart_last_1d_count` BIGINT COMMENT '最近1日被加入购物车次数',`cart_last_7d_count` BIGINT COMMENT '最近7日被加入购物车次数',`cart_last_30d_count` BIGINT COMMENT '最近30日被加入购物车次数',`cart_count` BIGINT COMMENT '累积被加入购物车次数',`favor_last_1d_count` BIGINT COMMENT '最近1日被收藏次数',`favor_last_7d_count` BIGINT COMMENT '最近7日被收藏次数',`favor_last_30d_count` BIGINT COMMENT '最近30日被收藏次数',`favor_count` BIGINT COMMENT '累积被收藏次数',`appraise_last_1d_good_count` BIGINT COMMENT '最近1日好评数',`appraise_last_1d_mid_count` BIGINT COMMENT '最近1日中评数',`appraise_last_1d_bad_count` BIGINT COMMENT '最近1日差评数',`appraise_last_1d_default_count` BIGINT COMMENT '最近1日默认评价数',`appraise_last_7d_good_count` BIGINT COMMENT '最近7日好评数',`appraise_last_7d_mid_count` BIGINT COMMENT '最近7日中评数',`appraise_last_7d_bad_count` BIGINT COMMENT '最近7日差评数',`appraise_last_7d_default_count` BIGINT COMMENT '最近7日默认评价数',`appraise_last_30d_good_count` BIGINT COMMENT '最近30日好评数',`appraise_last_30d_mid_count` BIGINT COMMENT '最近30日中评数',`appraise_last_30d_bad_count` BIGINT COMMENT '最近30日差评数',`appraise_last_30d_default_count` BIGINT COMMENT '最近30日默认评价数',`appraise_good_count` BIGINT COMMENT '累积好评数',`appraise_mid_count` BIGINT COMMENT '累积中评数',`appraise_bad_count` BIGINT COMMENT '累积差评数',`appraise_default_count` BIGINT COMMENT '累积默认评价数')COMMENT '商品主题宽表'
PARTITIONED BY (`dt` STRING)
STORED AS PARQUET
LOCATION '/warehouse/gmall/dwt/dwt_sku_topic/'
TBLPROPERTIES ("parquet.compression"="lzo");

2)数据装载

(1)首日装载

insert overwrite table dwt_sku_topic partition(dt='2020-06-14')
selectid,nvl(order_last_1d_count,0),nvl(order_last_1d_num,0),nvl(order_activity_last_1d_count,0),nvl(order_coupon_last_1d_count,0),nvl(order_activity_reduce_last_1d_amount,0),nvl(order_coupon_reduce_last_1d_amount,0),nvl(order_last_1d_original_amount,0),nvl(order_last_1d_final_amount,0),nvl(order_last_7d_count,0),nvl(order_last_7d_num,0),nvl(order_activity_last_7d_count,0),nvl(order_coupon_last_7d_count,0),nvl(order_activity_reduce_last_7d_amount,0),nvl(order_coupon_reduce_last_7d_amount,0),nvl(order_last_7d_original_amount,0),nvl(order_last_7d_final_amount,0),nvl(order_last_30d_count,0),nvl(order_last_30d_num,0),nvl(order_activity_last_30d_count,0),nvl(order_coupon_last_30d_count,0),nvl(order_activity_reduce_last_30d_amount,0),nvl(order_coupon_reduce_last_30d_amount,0),nvl(order_last_30d_original_amount,0),nvl(order_last_30d_final_amount,0),nvl(order_count,0),nvl(order_num,0),nvl(order_activity_count,0),nvl(order_coupon_count,0),nvl(order_activity_reduce_amount,0),nvl(order_coupon_reduce_amount,0),nvl(order_original_amount,0),nvl(order_final_amount,0),nvl(payment_last_1d_count,0),nvl(payment_last_1d_num,0),nvl(payment_last_1d_amount,0),nvl(payment_last_7d_count,0),nvl(payment_last_7d_num,0),nvl(payment_last_7d_amount,0),nvl(payment_last_30d_count,0),nvl(payment_last_30d_num,0),nvl(payment_last_30d_amount,0),nvl(payment_count,0),nvl(payment_num,0),nvl(payment_amount,0),nvl(refund_order_last_1d_count,0),nvl(refund_order_last_1d_num,0),nvl(refund_order_last_1d_amount,0),nvl(refund_order_last_7d_count,0),nvl(refund_order_last_7d_num,0),nvl(refund_order_last_7d_amount,0),nvl(refund_order_last_30d_count,0),nvl(refund_order_last_30d_num,0),nvl(refund_order_last_30d_amount,0),nvl(refund_order_count,0),nvl(refund_order_num,0),nvl(refund_order_amount,0),nvl(refund_payment_last_1d_count,0),nvl(refund_payment_last_1d_num,0),nvl(refund_payment_last_1d_amount,0),nvl(refund_payment_last_7d_count,0),nvl(refund_payment_last_7d_num,0),nvl(refund_payment_last_7d_amount,0),nvl(refund_payment_last_30d_count,0),nvl(refund_payment_last_30d_num,0),nvl(refund_payment_last_30d_amount,0),nvl(refund_payment_count,0),nvl(refund_payment_num,0),nvl(refund_payment_amount,0),nvl(cart_last_1d_count,0),nvl(cart_last_7d_count,0),nvl(cart_last_30d_count,0),nvl(cart_count,0),nvl(favor_last_1d_count,0),nvl(favor_last_7d_count,0),nvl(favor_last_30d_count,0),nvl(favor_count,0),nvl(appraise_last_1d_good_count,0),nvl(appraise_last_1d_mid_count,0),nvl(appraise_last_1d_bad_count,0),nvl(appraise_last_1d_default_count,0),nvl(appraise_last_7d_good_count,0),nvl(appraise_last_7d_mid_count,0),nvl(appraise_last_7d_bad_count,0),nvl(appraise_last_7d_default_count,0),nvl(appraise_last_30d_good_count,0),nvl(appraise_last_30d_mid_count,0),nvl(appraise_last_30d_bad_count,0),nvl(appraise_last_30d_default_count,0),nvl(appraise_good_count,0),nvl(appraise_mid_count,0),nvl(appraise_bad_count,0),nvl(appraise_default_count,0)
from
(selectidfrom dim_sku_infowhere dt='2020-06-14'
)t1
left join
(selectsku_id,sum(if(dt='2020-06-14',order_count,0)) order_last_1d_count,sum(if(dt='2020-06-14',order_num,0)) order_last_1d_num,sum(if(dt='2020-06-14',order_activity_count,0)) order_activity_last_1d_count,sum(if(dt='2020-06-14',order_coupon_count,0)) order_coupon_last_1d_count,sum(if(dt='2020-06-14',order_activity_reduce_amount,0)) order_activity_reduce_last_1d_amount,sum(if(dt='2020-06-14',order_coupon_reduce_amount,0)) order_coupon_reduce_last_1d_amount,sum(if(dt='2020-06-14',order_original_amount,0)) order_last_1d_original_amount,sum(if(dt='2020-06-14',order_final_amount,0)) order_last_1d_final_amount,sum(if(dt>=date_add('2020-06-14',-6),order_count,0)) order_last_7d_count,sum(if(dt>=date_add('2020-06-14',-6),order_num,0)) order_last_7d_num,sum(if(dt>=date_add('2020-06-14',-6),order_activity_count,0)) order_activity_last_7d_count,sum(if(dt>=date_add('2020-06-14',-6),order_coupon_count,0)) order_coupon_last_7d_count,sum(if(dt>=date_add('2020-06-14',-6),order_activity_reduce_amount,0)) order_activity_reduce_last_7d_amount,sum(if(dt>=date_add('2020-06-14',-6),order_coupon_reduce_amount,0)) order_coupon_reduce_last_7d_amount,sum(if(dt>=date_add('2020-06-14',-6),order_original_amount,0)) order_last_7d_original_amount,sum(if(dt>=date_add('2020-06-14',-6),order_final_amount,0)) order_last_7d_final_amount,sum(if(dt>=date_add('2020-06-14',-29),order_count,0)) order_last_30d_count,sum(if(dt>=date_add('2020-06-14',-29),order_num,0)) order_last_30d_num,sum(if(dt>=date_add('2020-06-14',-29),order_activity_count,0)) order_activity_last_30d_count,sum(if(dt>=date_add('2020-06-14',-29),order_coupon_count,0)) order_coupon_last_30d_count,sum(if(dt>=date_add('2020-06-14',-29),order_activity_reduce_amount,0)) order_activity_reduce_last_30d_amount,sum(if(dt>=date_add('2020-06-14',-29),order_coupon_reduce_amount,0)) order_coupon_reduce_last_30d_amount,sum(if(dt>=date_add('2020-06-14',-29),order_original_amount,0)) order_last_30d_original_amount,sum(if(dt>=date_add('2020-06-14',-29),order_final_amount,0)) order_last_30d_final_amount,sum(order_count) order_count,sum(order_num) order_num,sum(order_activity_count) order_activity_count,sum(order_coupon_count) order_coupon_count,sum(order_activity_reduce_amount) order_activity_reduce_amount,sum(order_coupon_reduce_amount) order_coupon_reduce_amount,sum(order_original_amount) order_original_amount,sum(order_final_amount) order_final_amount,sum(if(dt='2020-06-14',payment_count,0)) payment_last_1d_count,sum(if(dt='2020-06-14',payment_num,0)) payment_last_1d_num,sum(if(dt='2020-06-14',payment_amount,0)) payment_last_1d_amount,sum(if(dt>=date_add('2020-06-14',-6),payment_count,0)) payment_last_7d_count,sum(if(dt>=date_add('2020-06-14',-6),payment_num,0)) payment_last_7d_num,sum(if(dt>=date_add('2020-06-14',-6),payment_amount,0)) payment_last_7d_amount,sum(if(dt>=date_add('2020-06-14',-29),payment_count,0)) payment_last_30d_count,sum(if(dt>=date_add('2020-06-14',-29),payment_num,0)) payment_last_30d_num,sum(if(dt>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/43157.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

MinIO - 服务端签名直传(前端 + 后端 + 效果演示)

目录 开始 服务端签名直传概述 代码实现 后端实现 前端实现 效果演示 开始 服务端签名直传概述 传统的&#xff0c;我们有两种方式将图片上传到 OSS&#xff1a; a&#xff09;前端请求 -> 后端服务器 -> OSS 好处&#xff1a;在服务端上传&#xff0c;更加安全…

Android - 云游戏本地悬浮输入框实现

一、简述 云游戏输入法分两种情况,以云化原神为例,分为 云端输入法 和 本地输入法,运行效果如下: 云端输入法本地输入法云端输入法 就是运行在云端设备上的输入法,对于不同客户端来说(Android、iPhone),运行效果一致。 本地输入法 则是运行在用户侧设备上的输入法,对…

Fastapi在docekr中进行部署之后,uvicorn占用的CPU非常高

前一段接点小活&#xff0c;做点开发&#xff0c;顺便学了学FASTAPI框架&#xff0c;对比flask据说能好那么一些&#xff0c;至少并发什么的不用研究其他的asgi什么的&#xff0c;毕竟不是专业开发&#xff0c;能少研究一个东西就省了很多的事。 但是部署的过程中突然之间在do…

Zabbix分布式监控

目录 分布式监控架构 实现分布式监控的步骤 优点和应用场景 安装Zabbix_Proxy Server端Web页面配置 测试 Zabbix 的分布式监控架构允许在大规模和地理上分散的环境中进行高效的监控。通过分布式监控&#xff0c;Zabbix 可以扩展其监控能力&#xff0c;支持大量主机和设备…

基于全志Orangepi Zero 2 的语音刷抖音项目

目录 一、硬件连接 二、项目实现功能 三、SU-03T语音模块的配置和烧录 3.1 创建产品&#xff1a; 3.2 设置PIN引脚为串口模式&#xff1a; 3.3 设置唤醒词&#xff1a; 3.4 设置指令语句&#xff1a; 3.5 设置控制详情&#xff1a; 3.6 发音人配置&#xff1a; 3.7 其…

atcoder 357 F Two Sequence Queries (线段树板子)

题目&#xff1a; 分析&#xff1a; 线段树 代码&#xff1a; // Problem: F - Two Sequence Queries // Contest: AtCoder - SuntoryProgrammingContest2024&#xff08;AtCoder Beginner Contest 357&#xff09; // URL: https://atcoder.jp/contests/abc357/tasks/abc357_…

华为HCIP Datacom H12-821 卷29

1.多选题 下面关于LSA age字段&#xff0c;描述正确的是∶ A、LSA age的单位为秒&#xff0c;在LSDB中的LSA的LS age随时间增长而增长 B、LSA age的单位为秒&#xff0c;在LSDB中的LSA的LS age随时间增长而减少 C、如果一条LSA的LS age达到了LS RefreshTime&#xff08…

[spring] Spring MVC - security(下)

[spring] Spring MVC - security&#xff08;下&#xff09; callback 一下&#xff0c;当前项目结构如下&#xff1a; 这里实现的功能是连接数据库&#xff0c;大范围和 [spring] rest api security 重合 数据库连接 - 明文密码 第一部分使用明文密码 设置数据库 主要就是…

内存与硬盘(笔记)

文章目录 1. 内存① 笔记② 相关软件 2. 硬盘① 笔记② 相关软件 3. 区别&#xff1a;4. 推荐 1. 内存 ① 笔记 ① 笔记本的内存条和台式机的内存条是不互通的 ② 我们常说的内存其实指的是运行内存(前台后台同时能运行多少APP) ③ 下图来自京东&#xff1a; 解析&#xff1…

ubuntu 分区情况

ubuntu系统安装与分区指南 - Philbert - 博客园 (cnblogs.com)https://www.cnblogs.com/liangxuran/p/14872811.html 详解安装Ubuntu Linux系统时硬盘分区最合理的方法-腾讯云开发者社区-腾讯云 (tencent.com)https://cloud.tencent.com/developer/article/1711884

终于找到了免费的C盘清理软件(极智C盘清理)

搜了很久&#xff0c;终于让我找到了一款 完全免费的C盘清理软件&#xff08;极智C盘清理&#xff09;。 点击前往官网免费使用极智C盘清理软件&#xff1a; C盘清理 用户好评 完全免费的极智C盘清理 用极智C盘清理清理了下系统的临时文件、缓存等无用数据文件&#xff0c;C盘终…

设计资料:520-基于ZU15EG 适配AWR2243的雷达验证底板 高速信号处理板 AWR2243毫米波板

基于ZU15EG 适配AWR2243的雷达验证底板 一、板卡概述 本板卡系北京太速科技自主研发&#xff0c;基于MPSOC系列SOC XCZU15EG-FFVB1156架构&#xff0c;搭载两组64-bit DDR4&#xff0c;每组容量32Gb&#xff0c;最高可稳定运行在2400MT/s。另有1路10G SFP光纤接口、1路40G…

使用F1C200S从零制作掌机之构建debian文件系统

前情&#xff1a;使用buildrootfs构建的文件系统调试了很久NES模拟器&#xff0c;执行InfoNES模拟器的时候一直黑屏&#xff0c;无内容显示&#xff0c;调不通了&#xff0c;所以改用debian系统试试。 一、环境配置 首先下载两个工具&#xff1a;qemu-arm-static和debootstra…

uniapp小程序上传文件

需求 小程序需要上传用户相册图片或拍摄的照片到后端服务器 uniapp官方处理小程序文件方法 选择文件方法&#xff1a;uni.chooseMedia uni-app官网uni-app,uniCloud,serverless,uni.chooseVideo(OBJECT),chooseVideo HarmonyOS 兼容性,uni.chooseMedia(OBJECT),uni.saveVid…

Android:如何绘制View

点击查看Android 如何绘制视图官网 一、简介 Android 框架会在 Activity 获得焦点时请求 Activity 绘制其布局。Android 框架会处理绘制流程&#xff0c;但该 Activity 必须提供其布局层次结构的根节点。 Android 框架会绘制布局的根节点&#xff0c;并测量和绘制布局树。它会…

React@16.x(51)路由v5.x(16)- 手动实现文件目录参考

作为前面几篇文章的参考&#xff1a; 实现 Router实现 Route实现 Switch实现 withRouter实现 Link 和 NavLink 以上。

一.4 处理器读并解释储存在内存中的指令

此刻&#xff0c;hello.c源程序已经被编译系统翻译成了可执行目标文件hello&#xff0c;并被存放在硬盘上。要想在Unix系统上运行该可执行文件&#xff0c;我们将它的文件名输入到称为shell的应用程序中&#xff1a; linux>./hello hello, world linux> shell是一个命令…

一.2.(4)放大电路静态工作点的稳定;

1.Rb对Q点及Au的影响 输入特性曲线&#xff1a;Rb减少&#xff0c;IBQ&#xff0c;UBEQ增大 输出特性曲线&#xff1a;ICQ增大&#xff0c;UCEQ减少 AUUO/Ui分子减少&#xff0c;分母增大&#xff0c;但由于分子带负号&#xff0c;所以|Au|减少 2.Rc对Q点及Au的影响 输入特性曲…

用Vue3和Plotly.js绘制交互式3D小提琴图

本文由ScriptEcho平台提供技术支持 项目地址&#xff1a;传送门 Vue 中使用 Plotly.js 创建小提琴图 应用场景介绍 小提琴图是一种统计图&#xff0c;用于显示数据的分布和中心趋势。它结合了箱线图和密度图的特点&#xff0c;可以直观地展示数据的分散性和形状。 代码基本…

使用Keil 点亮LED灯 F103ZET6

1.新建项目 不截图了 2.startup_stm32f10x_hd.s Keil\Packs\Keil\STM32F1xx_DFP\2.2.0\Device\Source\ARM 搜索startup_stm32f10x_hd.s 复制到项目路径&#xff0c;双击Source Group 1 3.项目文件夹新建stm32f10x.h&#xff0c; 新建文件main.c #include "stm32f10x…