[数仓]四、离线数仓(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.rhkb.cn/news/374303.html

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

相关文章

九.核心动画 - 显式动画

引言 本篇博客紧接着上一篇的隐式动画开始介绍显式动画。隐式动画是创建动态页面的一种简单的直接的方式&#xff0c;也是UIKit的动画机制基础。但是它并不能涵盖所有的动画类型。 显式动画 接下来我们就来研究另外一种动画显式动画&#xff0c;它能够对一些属性做指定的动画…

揭秘”大模型加速器”如何助力大模型应用

文章目录 一、大模型发展面临的问题二、“大模型加速器”助力突破困难2.1 现场效果展示2.1.1 大模型加速器——文档解析引擎2.2.2 图表数据提取 三、TextIn智能文档处理平台3.1 在线免费体验3.1.1 数学公式提取3.1.2 表格数据提取 四、acge文本向量化模型4.1 介绍4.2 技术创新4…

从0开始的STM32HAL库学习2

外部中断(HAL库GPIO讲解) 今天我们会详细地学习STM32CubeMX配置外部中断&#xff0c;并且讲解HAL库的GPIO的各种函数。 准备工作&#xff1a; 1、STM32开发板&#xff08;我的是STM32F103C8T6&#xff09; 2、STM32CubeMx软件、 IDE&#xff1a; Keil软件 3、STM32F1xx/ST…

前端使用Vue和Element实现可拖动弹框效果,且不影响底层元素操作,Cesium作为底图(可拖拽的视频实时播放弹框,底层元素可以正常操作)

简述&#xff1a;在前端开发中&#xff0c;弹框和实时视频播放是常见的需求。这里来简单记录一下&#xff0c;如何使用Vue.js和Element UI实现一个可拖动的弹框&#xff0c;并在其中播放实时视频。同时&#xff0c;确保在拖拽弹框时&#xff0c;底层元素仍然可以操作。这里来记…

Effective C++笔记之二十一:One Definition Rule(ODR)

ODR细节有点复杂&#xff0c;跨越各种情况。基本内容如下&#xff1a; ●普通&#xff08;非模板&#xff09;的noninline函数和成员函数、noninline全局变量、静态数据成员在整个程序中都应当只定义一次。 ●class类型&#xff08;包括structs和unions&#xff09;、模板&…

钡铼4G无线RTU助力智慧能源发展实现电网远程调控

随着全球对清洁能源和高效能源管理的需求日益增长&#xff0c;智慧能源技术正逐渐成为推动可持续发展的重要驱动力。在这一背景下&#xff0c;钡铼4G无线远程终端单元正在为智慧能源的发展和电网的远程调控提供强有力的支持。 钡铼4G无线RTU&#xff1a;智慧能源的神经网络 钡…

顺序结构 ( 五 ) —— 数据输入输出 【互三互三】

文章目录 &#x1f341;序 &#x1f341;一、字符输入函数getchar &#x1f341;二、字符输出函数putchar &#x1f341;三、通过cout流输出数据 &#x1f341;四、通过cin流读入数据 &#x1f341;五、格式化输入函数scanf &#x1f341;六、格式化输出函数printf &…

【python】QWidget父子关系,控件显示优先级原理剖析与应用实战演练

✨✨ 欢迎大家来到景天科技苑✨✨ &#x1f388;&#x1f388; 养成好习惯&#xff0c;先赞后看哦~&#x1f388;&#x1f388; &#x1f3c6; 作者简介&#xff1a;景天科技苑 &#x1f3c6;《头衔》&#xff1a;大厂架构师&#xff0c;华为云开发者社区专家博主&#xff0c;…

【C语言】C语言编译链接和Win32API简单介绍

目录 翻译环境和运行环境翻译环境编译器预处理&#xff08;预编译&#xff09;编译链接 执行环境 Win32API是什么控制台程序控制台获取坐标COORDGetStdHandle函数GetConsoleCursorinfo函数CONSOLE_CURSOR_INFOSetConsoleCursorInfo函数SetConsoleCursorPostion函数GetAsyncKeyS…

数字化时代的供应链管理综合解决方案

目录 引言背景与意义供应链管理综合解决方案的目标 &#x1f4c4;供应链管理系统主要功能系统优势 &#x1f4c4;物流管理系统主要功能系统优势 &#x1f4c4;订单管理系统主要功能应用场景 &#x1f4c4;仓储管理系统系统亮点主要功能系统优势 &#x1f4c4;商城管理系统主要功…

【MyBatis】——入门基础知识必会内容

&#x1f3bc;个人主页&#xff1a;【Y小夜】 &#x1f60e;作者简介&#xff1a;一位双非学校的大二学生&#xff0c;编程爱好者&#xff0c; 专注于基础和实战分享&#xff0c;欢迎私信咨询&#xff01; &#x1f386;入门专栏&#xff1a;&#x1f387;【MySQL&#xff0…

MySql性能调优01-[数据结构和索引]

数据结构和索引 什么是索引索引的种类常见索引数据结构和区别二叉树 红黑树 什么是索引 索引的种类 在Mysql中索引是在存储引擎层实现的&#xff0c;而不是在服务层实现的 按数据结构分&#xff1a;Btree索引、Hash索引、Full-text索引按存储结构分&#xff1a;聚簇索引、非聚…

数据结构——约瑟夫环C语言链表实现

约瑟夫环问题由古罗马史学家约瑟夫&#xff08;Josephus&#xff09;提出&#xff0c;他参加并记录了公元66—70年犹太人反抗罗马的起义。在城市沦陷之后&#xff0c;他和40名死硬的将士在附近的一个洞穴中避难。起义者表示“宁为玉碎不为瓦全”&#xff0c;约瑟夫则想“留得青…

go语言Gin框架的学习路线(六)

gin的路由器 Gin 是一个用 Go (Golang) 编写的 Web 框架&#xff0c;以其高性能和快速路由能力而闻名。在 Gin 中&#xff0c;路由器是框架的核心组件之一&#xff0c;负责处理 HTTP 请求并将其映射到相应的处理函数上。 以下是 Gin 路由器的一些关键特性和工作原理的简要解释…

第十八章 Express multer 文件上传

本章将学习Express multer 文件上传 &#xff0c;因为Nest 的文件上传是基于 Express 的中间件 multer 实现的&#xff0c;所以在学习 Nest 文件上传之前&#xff0c;我们先学习下 multer 包 首先先创建 multer-test 文件夹执行下面代码 创建package.json npm init -y接着安装…

单例模式的简单理解

单例模式 前言一、单例模式是什么二、单例模式的使用饿汉模式单线程下的懒汉模式多线程下的懒汉模式&#xff08;优化懒汉模式&#xff09;加锁 三、总结 前言 设计模式是将一些经典的问题场景进行整合归纳&#xff0c;并提供一些解决方案&#xff0c;相当于一种“套路”。 熟…

数据仓库介绍_维度表(三)

维度表概述 维度表是维度建模的基础和灵魂。前文提到&#xff0c;事实表紧紧围绕业务过程进行设计&#xff0c;而维度表则围绕业务过程所处的环境进行设计。维度表主要包含一个主键和各种维度字段&#xff0c;维度字段称为维度属性。 表设计步骤 确定维度&#xff08;表&…

SQL 针对上面的salaries表emp_no字段创建索引idx_emp_no

系列文章目录 文章目录 系列文章目录前言 前言 前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。点击跳转到网站&#xff0c;这篇文章男女通用&#xff0c;看懂了就去分享给你的码吧。 描述 针对salaries…

【开源合规】开源许可证风险场景详细解读

文章目录 前言关于BlackDuck许可证风险对比图弱互惠型许可证举个例子具体示例LGPL系列LGPL-2.0-onlyLGPL-2.0-or-laterLGPL-2.1-onlyLGPL-2.1-or-laterLGPL-3.0-onlyLGPL-3.0-or-laterMPL系列MPL-1.0MPL-1.1MPL-2.0EPL系列EPL-1.0EPL-2.0互惠型许可证GPL系列GPL-1.0GPL-2.0GPL-…

3.相机标定原理及代码实现(opencv)

1.相机标定原理 相机参数的确定过程就叫做相机标定。 1.1 四大坐标系及关系 &#xff08;1&#xff09;像素坐标系&#xff08;单位&#xff1a;像素&#xff08;pixel&#xff09;&#xff09; 像素坐标系是指相机拍到的图片的坐标系&#xff0c;以图片的左上角为坐标原点&a…