采用用户行为宽表作为DWS层
2.1 建表语句
drop table if exists ads_order2pay_mn; create external table ads_order2pay_mn ( `dt` string COMMENT ‘统计日期‘, `order_u_count` bigint COMMENT ‘下单人数‘, `payment_u_count` bigint COMMENT ‘支付人数‘, `order2payment_convert_ratio` decimal(10,2) COMMENT ‘下单到支付的转化率‘ ) COMMENT ‘‘ row format delimited fields terminated by ‘\t‘ location ‘/warehouse/gmall/ads/ ads_order2pay_mn /‘;
2.2 导入数据
-----------------------------需求--统计每个月订单付款率---------------------
订单付款率: 订单支付数 / 订单下单数
-----------------------------相关表---------------------
dws_user_action(推荐): 每个用户每天的下单数和支付数
-----------------------------思路-----------------------
取一个月,所有用户的下单数累加,和所有用户的支付数累加
-----------------------------SQL------------------------
insert into TABLE ads_order2pay_mn
SELECT
‘2020-02-16‘,
sum(order_count) order_u_count,
sum(payment_count) payment_u_count,
cast(sum(payment_count)/ sum(order_count) * 100 as decimal(10,2)) order2payment_convert_ratio
from dws_user_action
where date_format(dt,‘yyyy-MM‘)=date_format(‘2020-02-16‘,‘yyyy-MM‘)
大数据实战(六十):电商数仓(四十三)之系统业务数据仓库(十六)统计每个月订单付款率
原文:https://www.cnblogs.com/qiu-hua/p/13548975.html