电商项目之支付类指标统计表 SQL 实现|学习笔记

简介: 快速学习电商项目之支付类指标统计表 SQL 实现

开发者学堂课程【新电商大数据平台2020最新课程电商项目之支付类指标统计表 SQL 实现】学习笔记,与课程紧密联系,让用户快速学习知识。

课程地址https://developer.aliyun.com/learning/course/640/detail/10567


电商项目之支付类指标统计表 SQL 实现

 

支付类指标统计表

先创建 sql

with orders as(

select

oc.customer. gender,

oc .customer_age_range,

oc .customer_natives,

od.pay_ type,

od.pay_ nettype,

sum(od .payment_money) order_ amounts, - -支付金额

count(distinct od.customer_id) order_user_counts --支付用户

count(distinct od.product_code) pay_product_counts --支付商品

先找到交易流水表

from

dwd_ nshop . dwd_ nshop_orders_ details od

join

ods_ nshop.ods_ 02_customer oc

on

od.customer_ id=oc .customer_id

where

od. bdp_day=" 20200321 "

group by 取值范围

oc .customer_gender,

oc .customer_age_range,

oc .customer_natives,

od.pay_ type,

od.pay_ nettype

),

pay as(

select

oc .customer_gender,

oc .customer_age_range,

oc .customer_natives,

op.pay_ type,

op.pay_ nettype,

sum(od.payment_money) order_amounts,--支付金额

count(distinct odcustomer id) order_ user_counts, –支付用户

count(distinct od.customer code) pay_product_counts—支付商品数

from

dwd_nshop.dwd_nshop_orders_details od

join

ods_nshop.ods_e2_customer oc

on

od.customer_id=oc.customer_id

where

od .bdp_day= " 20200321"

group by

oc.customer_gender,

oc.customer_age_range,

oc.customer_natives,

od.pay_type,

od.pay_nettype

以上是第一步。

第二步求支付的详细信息,需要拿到原始数据表。

Pay sa(

Select

oc .customer_gender,

oc .customer_age_range,

oc .customer_natives,

op.pay_ type,

op.pay_ nettype

sum(case when op.pay_ status-1 then op.pay_ amount end) pay_ amounts,(根据状态进行判断)

sum(case when op.pay_ status-1 then 1 end) psy_success,

sum(case when op.pay_ status-0 then 1 end) psy_fail,

count(distinct op.order_id) pay_ order_counts ,(支付订单id)

count(distinct op.customer id) pay_ user_counts(支付的用户)

from

ods_ nshop.ods_ 02_orders_ pay_records op

join

ods_ nshop.ods_ 02_ customer oc

on

op.customer_ id=oc .customer_id

where

from_unixtine(cast(op.pay_ctime/1000 as int),’yyyyMMdd’ )= ' 20191102'

group by

oc .customer_gender,

oc .customer_age_range,

oc .customer_natives,

op.pay_ type,

op.pay_ nettype

select

from

join

orders

on

orders .customer _gender=pay. customer _gender

and

orders .customer _age_range=pay .customer _age_ range

and

orders.customer _natives=pay . customer _natives

and

orders.pay_ type=pay.pay _type

and

orders .pay_ nettype=pay .pay_nettype

查询一下时间,以防错误

Time taken : 0.164 seconds

hive> select from_unixtime(cast(op.pay_ctime/1000 as int) , yyywdd' ) from ods_nshop.ods_02_orders_pay_records op limit 10;

oK

Time taken : 0.164 seconds

hive> select from_unixtime(cast(op.pay_ctime/1000 as int) , yyywdd' ) from ods_nshop.ods_02_orders_pay_records op limit 10;

oK

20191102201911022019110220191102201911022019110220191102201911022019110220191102

Time taken : 0.094 seconds,Fetched: 10 row(s)hive>.

insert overwrite table ads. nshop.ads_ nshop_ pay_ stat_ gsets partition(bdp_day=' 20200321 )

from

join

orders

on

orders .customer _gender=pay. customer _gender

and

orders .customer _age_range=pay .customer _age_ range

and

orders.customer _natives=pay . customer _natives

and

orders.pay_ type=pay.pay _type

and

orders .pay_ nettype=pay .pay_nettype

select

pay.customer_gender

pay.customer_age_range,

pay.customer_natives,

pay.pay_type,

pay.pay_nettype,

pay.pay_ amounts,(支付金额)

pay.psy_ success,(支付成功数)

pay.psy_ fail,(支付失败数)

pay.pay_ order_counts,(支付订单数)

pay.pay_ user_counts,(支付用户数)

orders .pay_ product_counts,(支付商品数)

pay.pay_ amounts/orders.order_amounts order _pay_ anount_rate,(支付成功率应该用支付成功除以未支付成功的)

pay.pay_user_counts/orders.order_user_counts order pay_ user_rate

from

pay

join

orders

on

复制全部进 sercue 语句,注意要修改错别字,运行的时候要稍微等待一下,时间有点久。

运行结果:

其中有一些空的内容

image.png

将其补全;

insert overwrite table ads_nshop.ads_nshop_pay_stat_gsets partition(bdp_day- '20200321)

求支付类指标统计表的意义,提高用户体验度。

相关文章
|
3月前
|
算法 数据挖掘 数据库
通过 SQL 快速使用 OceanBase 向量检索学习笔记
通过 SQL 快速使用 OceanBase 向量检索学习笔记
|
3月前
|
SQL 数据库
SQL 学习笔记 - 多表关系与多表查询
数据库多表关系包括一对多、多对多和一对一,常用外键关联。多表查询方式有隐式/显式内连接、外连接、子查询等,支持别名和条件筛选。子查询分为标量、列、行、表子查询,常用于复杂查询场景。
|
关系型数据库 MySQL 网络安全
5-10Can't connect to MySQL server on 'sh-cynosl-grp-fcs50xoa.sql.tencentcdb.com' (110)")
5-10Can't connect to MySQL server on 'sh-cynosl-grp-fcs50xoa.sql.tencentcdb.com' (110)")
|
SQL 存储 监控
SQL Server的并行实施如何优化?
【7月更文挑战第23天】SQL Server的并行实施如何优化?
563 13
解锁 SQL Server 2022的时间序列数据功能
【7月更文挑战第14天】要解锁SQL Server 2022的时间序列数据功能,可使用`generate_series`函数生成整数序列,例如:`SELECT value FROM generate_series(1, 10)。此外,`date_bucket`函数能按指定间隔(如周)对日期时间值分组,这些工具结合窗口函数和其他时间日期函数,能高效处理和分析时间序列数据。更多信息请参考官方文档和技术资料。
379 9
|
SQL 存储 网络安全
关系数据库SQLserver 安装 SQL Server
【7月更文挑战第26天】
273 6
|
SQL Oracle 关系型数据库
MySQL、SQL Server和Oracle数据库安装部署教程
数据库的安装部署教程因不同的数据库管理系统(DBMS)而异,以下将以MySQL、SQL Server和Oracle为例,分别概述其安装部署的基本步骤。请注意,由于软件版本和操作系统的不同,具体步骤可能会有所变化。
1211 3
|
存储 SQL C++
对比 SQL Server中的VARCHAR(max) 与VARCHAR(n) 数据类型
【7月更文挑战7天】SQL Server 中的 VARCHAR(max) vs VARCHAR(n): - VARCHAR(n) 存储最多 n 个字符(1-8000),适合短文本。 - VARCHAR(max) 可存储约 21 亿个字符,适合大量文本。 - VARCHAR(n) 在处理小数据时性能更好,空间固定。 - VARCHAR(max) 对于大文本更合适,但可能影响性能。 - 选择取决于数据长度预期和业务需求。
1201 1
|
SQL 存储 安全
数据库数据恢复—SQL Server数据库出现逻辑错误的数据恢复案例
SQL Server数据库数据恢复环境: 某品牌服务器存储中有两组raid5磁盘阵列。操作系统层面跑着SQL Server数据库,SQL Server数据库存放在D盘分区中。 SQL Server数据库故障: 存放SQL Server数据库的D盘分区容量不足,管理员在E盘中生成了一个.ndf的文件并且将数据库路径指向E盘继续使用。数据库继续运行一段时间后出现故障并报错,连接失效,SqlServer数据库无法附加查询。管理员多次尝试恢复数据库数据但是没有成功。
|
SQL 存储 测试技术