电商项目之总体运营指标统计表 SQL 实现|学习笔记

简介: 快速学习电商项目之总体运营指标统计表 SQL 实现

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

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


电商项目之总体运营指标统计表 SQL 实现

 

内容介绍:

一、关联页面布局表和商品信息表

二、求浏览次数

三、求下单次数

 

一、关联页面布局表和商品信息表

with pr as(  

select//取出页面布局表和商品信息表

from

ods_nshop.dim_pub_product pr//商品信息表

join

ods_nshop.dim_pub_page pp//页面布局表

on

pp.page_target=pr.product_code//关联页面布局表和商品信息表

where

pp.page_type='4'

),

然后再加入两个信息,在 from 上添加:

pp.page_code,

pr.category_code

最后需要通过这两个进行关联

 

二、求浏览次数

接着第二步求浏览次数,继续输入

pdview as(

select

from

dwd_nshop.dwd_nshop_actlog_pdtview pd//产品浏览表

join

ods_nshop.ods_02_customer oc

on

pd.user_id=oc.customer_id//条件

join

pr

on

pd.target_id=pr.page_code//取值

where//设置 where 条件

pd.bdp_day='20200321'

group by    //此处需要求数量需要分组聚合,需要求性别数量、年龄段、所在区域、category 四个字段

所以先取值,在 select 下输入

oc.customer_gender,

oc.customer_age_range,

oc.customer_natives,

pr.category_code,

count(1) pdview_count

再来 group 下分组,在 group 下继续输入

oc.customer_gender,

oc.customer_age_range,

oc.customer_natives,

pr.category_code

),

 

三、求下单次数

第三步是求下单次数,继续输入

od as(

select

from

dwd_nshop.dwd_nshop_orders_details od//交易订单明细流水表

join

ods_nshop.ods_02_customer oc

on

od.customer_id=oc.customer_id//条件

join

ods_nshop.dim_pub_product pr //通过页面布局表拿到 product_code,od 中有 product_code,可以直接join 商品信息表

on

pr.product_code=od.product_code

where

od.bdp_day='20200321‘

group by //与上表的维度分析一致

oc.customer_gender,

oc.customer_age_range,

oc.customer_natives,

pr.category_code,

)

然后将该四个字段依旧进行取值,在 select 下输入

oc.customer_gender,

oc.customer_age_range,

oc.customer_natives,

pr.category_code,

维度取到之后,还需要取几个值,先来取订单数量,继续输入

count(distinct od.order_id) order_counts,//求订单数量

sum(od.district_money) order_discounts,//计算优惠金额总数

sum(od.shipping_money) shipping_amounts,//计算运费金额总数

sum(od.payment_money) order_amounts, //计算支付金额总数

最后还可以通过总的金额去求最终的客单价,继续输入

sum(od.paywent_money)/count(distinct od.customer_id)per_customer_transaction //计算客单价

以上三个表完成后,最终来将以上表 join 在一起求下单率,输入

select

from

od

join

pdview

on

od.customer_gender=pdview.customer_gender

and

od.customer_age_range = pdview.customer_age_range

and

od.customer_natives=pdview.customer_natives

and

od.category_code=pdview.category_code

然后将 od 的每个值取出,在 select 下输入

od.customer_gender,

od.customer_age_range,

od.customer_natives,

od.category_code,

还需要第三步中的字段,继续输入

od.order_counts/pdview.pdview_count order_rate,//要计算下单率,od 的次数/pd 的浏览次数

od.order_amounts, //销售金额

od.order_discounts,   //优惠金额

od.shipping_amounts, //运费金额

od.per_customer_transaction  //客单价

运行整个 sql,存在拼写错误等,修改后等待运行结果,下节进行展示

相关文章
|
9月前
|
SQL 关系型数据库 MySQL
简简单单 My SQL 学习笔记(1)——表中数据的整删改查
简简单单 My SQL 学习笔记(1)——表中数据的整删改查
|
9月前
|
SQL 关系型数据库 MySQL
简简单单 My SQL 学习笔记(2)——分组和简单数据的查询
简简单单 My SQL 学习笔记(2)——分组和简单数据的查询
|
9月前
|
SQL 关系型数据库 MySQL
简简单单 My SQL 学习笔记(3)——连接和嵌套查询
简简单单 My SQL 学习笔记(3)——连接和嵌套查询
|
5月前
|
关系型数据库 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)")
|
7月前
|
SQL 存储 监控
SQL Server的并行实施如何优化?
【7月更文挑战第23天】SQL Server的并行实施如何优化?
182 13
|
7月前
|
SQL
解锁 SQL Server 2022的时间序列数据功能
【7月更文挑战第14天】要解锁SQL Server 2022的时间序列数据功能,可使用`generate_series`函数生成整数序列,例如:`SELECT value FROM generate_series(1, 10)。此外,`date_bucket`函数能按指定间隔(如周)对日期时间值分组,这些工具结合窗口函数和其他时间日期函数,能高效处理和分析时间序列数据。更多信息请参考官方文档和技术资料。
109 9
|
7月前
|
SQL 存储 网络安全
关系数据库SQLserver 安装 SQL Server
【7月更文挑战第26天】
93 6
|
7月前
|
存储 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) 对于大文本更合适,但可能影响性能。 - 选择取决于数据长度预期和业务需求。
584 1
|
7月前
|
SQL Oracle 关系型数据库
MySQL、SQL Server和Oracle数据库安装部署教程
数据库的安装部署教程因不同的数据库管理系统(DBMS)而异,以下将以MySQL、SQL Server和Oracle为例,分别概述其安装部署的基本步骤。请注意,由于软件版本和操作系统的不同,具体步骤可能会有所变化。
553 3
|
6月前
|
SQL 安全 Java
驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“The server selected protocol version TLS10 is not accepted by client
驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“The server selected protocol version TLS10 is not accepted by client
604 0