电商项目之总体运营指标统计表 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,存在拼写错误等,修改后等待运行结果,下节进行展示

相关文章
|
3月前
|
SQL 数据库管理
第二章:基础查询与排序---SQL学习笔记
第二章:基础查询与排序---SQL学习笔记
56 0
|
1月前
|
SQL Java 应用服务中间件
Java项目防止SQL注入的四种方案
Java项目防止SQL注入的四种方案
38 0
|
3月前
|
SQL OLAP Serverless
第五章:SQL高级处理---SQL学习笔记
第五章:SQL高级处理---SQL学习笔记
40 0
|
3月前
|
SQL 关系型数据库 MySQL
第四章:集合运算---SQL学习笔记
第四章:集合运算---SQL学习笔记
59 0
|
3月前
|
SQL 关系型数据库 数据库
第三章:复杂一点的查询--SQL学习笔记
第三章:复杂一点的查询--SQL学习笔记
68 0
|
3月前
|
SQL 关系型数据库 MySQL
第一章:初识数据库---SQL学习笔记
第一章:初识数据库---SQL学习笔记
66 0
|
3月前
|
SQL 关系型数据库 MySQL
MySQL8.0安装(win10) ---SQL学习笔记
MySQL8.0安装(win10) ---SQL学习笔记
40 0
|
12天前
|
SQL 人工智能 算法
【SQL server】玩转SQL server数据库:第二章 关系数据库
【SQL server】玩转SQL server数据库:第二章 关系数据库
51 10
|
1月前
|
SQL 数据库 数据安全/隐私保护
Sql Server数据库Sa密码如何修改
Sql Server数据库Sa密码如何修改
|
22天前
|
SQL
启动mysq异常The server quit without updating PID file [FAILED]sql/data/***.pi根本解决方案
启动mysq异常The server quit without updating PID file [FAILED]sql/data/***.pi根本解决方案
16 0