FineBI实战项目一(9):每日不同支付方式订单总额/订单笔数

1 明确数据分析目标

统计每种支付方式的订单个数以及订单总金额

2 创建用于保存数据分析结果的表

create table app_order_paytype(
    id int primary key auto_increment,
    dt date,
    pay_type varchar(20),
    total_money double,
    total_cnt int
);

3 编写SQL语句进行数据分析

select
	substring(createTime,1,10) as dt,-- 获取每一天的日期
	case payType when 1 then '支付宝' when 2 then '微信' when 3 then '现金' else '其他' end as pay_type,
	round(sum(realTotalMoney),2) as total_money, -- 分组后这一天的所有订单总金额
	count(orderId) as total_cnt -- 分组后这一天的订单总个数
from
	ods_finebi_orders
group by
	substring(createTime,1,10),payType;

4 加载到结果表中

insert into app_order_paytype
select
	null,
	substring(createTime,1,10) as dt,-- 获取每一天的日期
	case payType when 1 then '支付宝' when 2 then '微信' when 3 then '现金' else '其他' end as pay_type,
	round(sum(realTotalMoney),2) as total_money, -- 分组后这一天的所有订单总金额
	count(orderId) as total_cnt -- 分组后这一天的订单总个数
from
	ods_finebi_orders
group by
	substring(createTime,1,10),payType;

猜你喜欢

转载自blog.csdn.net/u013938578/article/details/135457372