2订单分析地域、分类维度分析业务开发
总结需求1:
ads数据都来源于dw, DW层数据都来源于ods。 ads一张表存储了18个需求的所有数据
2.1 需求分析
集团总公司分为很多的分公司(销售事业部)

为了公司的经营需要,公司需要定期检查各个分公司的经营指标完成情况,运营部门提出数据分析需求:
交易金额
交易笔数
微信交易笔数
支付宝交易笔数

维度如下:
商品分类
行政区域
要求:最终可以根据不同大区、不同城市、不能分类级别查询交易数据,也就是要求支持不同维度的组合查询。
需求:
获取全国、无商品分类维度的分交易类型数据
获取全国、无商品分类维度的不分交易类型的数据
获取全国、一级商品分类维度的分交易类型数据
获取全国、一级商品分类维度的不分交易类型数据
获取全国、二级商品分类维度的分交易类型数据
获取全国、二级商品不分类维度的分交易类型数据
获取大区、无商品分类维度的分交易类型数据
获取大区、无商品不分类维度的不分交易类型数据
获取大区、一级商品分类维度的分交易类型数据
获取大区、一级商品分类维度的不分交易类型数据
获取大区、二级商品分类维度的分交易类型数据
获取大区、二级商品分类维度的不分交易类型数据
获取城市、无商品分类维度的分交易类型数据
获取城市、无商品分类维度的不分交易类型数据
获取城市、一级商品分类维度的不分交易类型数据
获取城市、一级商品分类维度的分交易类型数据
获取城市、二级商品分类维度的不分交易类型数据
获取城市、二级商品分类维度的分交易类型数据

根据需求整理出用到的表
最终的流程图:

2.2 创建 ads 层数据表

– 创建ads(数据集市层)订单分析表
DROP TABLE IF EXISTS itcast_ads.ads_trade_order;
CREATE TABLE itcast_ads.ads_trade_order(
orgtype bigint,
orgid bigint,
cattype bigint,
catid bigint,
paytype bigint,
ordercount bigint,
goodsprice double)
PARTITIONED BY (dt string)
STORED AS PARQUET;

orgtype 区域类型
orgid 区域类型ID
cattype 品类
catid 品类ID
paytype 支付方式ordercount订单总数goodsprice` 订单金额
2.3 创建 dw 层数据表
该层主要创建维度表与事实表。为了便于识别,维度表增加 dim_ 前缀。事实表增加 fact_ 前缀
fact_orders

– 创建dw层订单事实表
DROP TABLE IF EXISTS itcast_dw.fact_orders;
CREATE TABLE itcast_dw.fact_orders(
orderid bigint,
orderno string,
userid bigint,
orderstatus bigint,
goodsmoney double,
delivertype bigint,
delivermoney double,
totalmoney double,
realtotalmoney double,
paytype bigint,
ispay bigint,
areaid bigint,
areaidpath string,
orderscore bigint,
isinvoice bigint,
invoiceclient string,
orderremarks string,
ordersrc bigint,
needpay double,
isrefund bigint,
isclosed bigint,
receivetime string,
deliverytime string,
tradeno string,
createtime string,
commissionfee double,
scoremoney double,
usescore bigint,
noticedeliver bigint,
lockcashmoney double,
paytime string,
isbatch bigint,
totalpayfee bigint)
partitioned by (dt string)
STORED AS PARQUET;

dim_goods
– dw层商品维度表,通过拉链表已经创建
dim_goods_cats

– 创建dw层商品分类维度表
DROP TABLE IF EXISTS itcast_dw.dim_goods_cats;
CREATE TABLE itcast_dw.dim_goods_cats(
catid bigint,
catname string,
parentid bigint,
isshow bigint,
isfloor bigint,
createtime bigint)
partitioned by (dt string,catLevel bigint)
STORED AS PARQUET;

dim_org

DROP TABLE IF EXISTS itcast_dw.dim_org;
CREATE TABLE itcast_dw.dim_org(
orgId bigint,
orgname string,
parentId bigint,
orglevele bigint,
managercode string,
createtime string,
updatetime string,
orgtype bigint)
PARTITIONED BY (dt string)
STORED AS PARQUET;

dim_shops

– 创建dw层商铺维度表
DROP TABLE IF EXISTS itcast_dw.dim_shops;
CREATE TABLE itcast_dw.dim_shops(
shopid bigint,
areaid bigint,
shopname string,
servicestarttime bigint,
serviceendtime bigint,
shopstatus bigint,
bdcode string)
partitioned by (dt string)
STORED AS PARQUET;

2.4 ods层数据至dw层
fact_orders
导入ods层 2019年09月09日的订单数据到 20190908 分区
导入数据后使用 hive/beeline确认数据是否正确映射

INSERT OVERWRITE TABLE itcast_dw.fact_orders PARTITION (dt=‘20190908’)
SELECT
orderid,
orderno,
userid,
orderstatus,
goodsmoney,
delivertype,
delivermoney,
totalmoney,
realtotalmoney,
paytype,
ispay,
areaid,
areaidpath,
orderscore,
isinvoice,
invoiceclient,
orderremarks,
ordersrc,
needpay,
isrefund,
isclosed,
receivetime,
deliverytime,
tradeno,
createtime,
commissionfee,
scoremoney,
usescore,
noticedeliver,
lockcashmoney,
paytime,
isbatch,
totalpayfee
FROM itcast_ods.itcast_orders
WHERE dt=‘20190908’;

测试:

select * from itcast_dw.fact_orders limit 5;


dim_goods
将商品表的所有数据加载到 商品维度表
参考代码:
– 测试

select * from itcast_dw.dim_goods where dw_end_date = ‘9999-12-31’ limit 5;

dim_goods_cats
分别将 ods 层的商品分类数据导入到 dw层的 dim_goods_cats 的不同分区中
注意分区字段为
odt (20190905)
ocatlvel (1、2、3)
参考代码:
– 3级分类

INSERT OVERWRITE TABLE itcast_dw.dim_goods_cats PARTITION (dt=‘20190908’,catlevel=‘3’)
SELECT
catid,
catname,
parentid,
isshow,
isfloor,
createtime
FROM itcast_ods.itcast_goods_cats WHERE cat_level=3 and dt=‘20190908’;

– 2级分类

INSERT OVERWRITE TABLE itcast_dw.dim_goods_cats PARTITION (dt=‘20190908’,catlevel=‘2’)
SELECT
catid,
catname,
parentid,
isshow,
isfloor,
createtime
FROM itcast_ods.itcast_goods_cats WHERE cat_level=2 and dt=‘20190908’;

– 1 级分类

INSERT OVERWRITE TABLE itcast_dw.dim_goods_cats PARTITION (dt=‘20190908’,catlevel=‘1’)
SELECT
catid,
catname,
parentid,
isshow,
isfloor,
createtime
FROM itcast_ods.itcast_goods_cats WHERE cat_level=1 and dt=‘20190908’;

– 测试

select * from itcast_ods.itcast_goods_cats WHERE cat_level=1 and dt=‘20190908’ limit 5;

select * from itcast_ods.itcast_goods_cats WHERE cat_level=2 and dt=‘20190908’ limit 5;

select * from itcast_ods.itcast_goods_cats WHERE cat_level=3 and dt=‘20190908’ limit 5;

dim_shops
将 ods层的 itcast_shops 数据导入到 dim_shops 的 20190908分区中
参考代码:

INSERT OVERWRITE TABLE itcast_dw.dim_shops PARTITION (dt=‘20190908’)
SELECT
shopid,
areaid,
shopname,
servicestarttime,
serviceendtime,
shopstatus,
bdcode
FROM itcast_ods.itcast_shops
where dt=‘20190908’;

– 测试

select * from itcast_dw.dim_shops where dt=‘20190908’ limit 5;

dim_org
将 ods 层 itcast_org 导入到 dw层中

INSERT OVERWRITE TABLE itcast_dw.dim_org PARTITION (dt=‘20190908’)
SELECT
orgid,
orgname,
parentid,
orglevel,
managercode,
createtime,
updatetime,
orgtype
FROM itcast_ods.itcast_org
WHERE dt = ‘20190908’;

– 测试

select * from itcast_dw.dim_org where dt = ‘20190908’ limit 5;

2.5 dw层数据维度拉宽
数据表拉宽
1、店铺维度数据拉宽
店铺表(itcast_shops)与组织机构表(itcast_org)进行关联

dim_shop

– 创建dw层商铺维度表
DROP TABLE IF EXISTS itcast_dw.dim_shop;
– 1. 店铺维度表
create table if not exists itcast_dw.dim_shop(
shop_id string, – 店铺id,
shop_name string, – 店铺名称
city_id string, --城市组织机构id
city_name string, --城市组织机构名称
region_id string, --区域组织机构id
region_name string --区域组织机构名称
)
partitioned by (dt string)

参考代码:

– 2. 加载订单组织机构维度表数据
insert overwrite table itcast_dw.dim_shop partition(dt=‘20190908’)
select
t1.shopid as shop_id, – 店铺id
t1.shopname as shop_name, – 店铺名称
t2.orgid as city_id, – 城市组织机构id
t2.orgname as city_name, – 城市组织机构名称
t3.orgid as region_id, – 区域组织机构id
t3.orgname as region_name – 区域组织机构名称
from
(select shopid, shopname, areaid from itcast_ods.itcast_shops where dt=‘20190908’) t1 – 店铺数据
left join
(select orgid, parentid, orgname, orglevel from itcast_ods.itcast_org where orglevel=2 and dt=‘20190908’) t2 – 城市组织机构数据
on t1.areaid = t2.orgid
left join
(select orgid, parentid, orgname, orglevel from itcast_ods.itcast_org where orglevel=1 and dt=‘20190908’) t3 – 省份组织机构数据
on t2.parentid = t3.orgid;

– 测试数据

select * from itcast_dw.dim_shop limit 10;

2、商品分类维度数据拉宽
dim_goods_cat
商品表维度数据拉宽
参考代码:

– 表创建
DROP TABLE IF EXISTS itcast_dw.dim_goods_cat;
create table if not exists itcast_dw.dim_goods_cat(
cat_3d_id string, – 三级商品分类id
cat_3d_name string, – 三级商品分类名称
cat_2d_id string, – 二级商品分类Id
cat_2d_name string, – 二级商品分类名称
cat_1t_id string, – 一级商品分类id
cat_1t_name string – 一级商品分类名称
)
partitioned by (dt string)
STORED AS PARQUET;

insert overwrite table itcast_dw.dim_goods_cat partition(dt=‘20190908’)
select
t3.catid as cat_3d_id, – 三级分类id
t3.catname as cat_3d_name, – 三级分类名称
t2.catid as cat_2d_id, – 二级分类id
t2.catname as cat_2d_name, – 二级分类名称
t1.catid as cat_1t_id, – 一级分类id
t1.catname as cat_1t_name – 一级分类名称
from
(select catid, catname, parentid from itcast_ods.itcast_goods_cats where cat_level=3 and dt=‘20190908’) t3 – 商品三级分类数据
left join
(select catid, catname, parentid from itcast_ods.itcast_goods_cats where cat_level=2 and dt=‘20190908’) t2 – 商品二级分类数据
on t3.parentid = t2.catid
left join
(select catid, catname, parentid from itcast_ods.itcast_goods_cats where cat_level=1 and dt=‘20190908’) t1 – 商品一级分类数据
on t2.parentid = t1.catid;

– 测试数据

select * from itcast_dw.dim_goods_cat limit 5;

3、支付方式维度表拉宽
dim_payment

0—其他
1—支付宝
2—微信
3—现金
41—额支付
42—货到付款

– 三、支付方式维度数据拉宽

– 1. 创建支付方式维度表
create table if not exists itcast_dw.dim_payment(
payment_id string, – 支付方式id
payment_name string – 支付方式名称
)
partitioned by (dt string)
STORED AS PARQUET;

– 2. 加载支付方式维度数据
– 需要额外添加一行数据 0 -> 其他
insert overwrite table itcast_dw.dim_payment partition(dt=‘20190908’)
select
t1.id as payment_id, – 支付方式id
t1.payName as payment_name – 支付方式名称
from
(select id, payName from itcast_ods.itcast_payments where dt=‘20190908’) t1
union
select
‘0’ as payment_id,
‘其他’ as payment_name;

– 测试查询支付方式维度数据

select * from itcast_dw.dim_payment limit 5;


4、事实表拉宽
fact_order_goods1

– 1. 创建订单明细事实表
create table if not exists itcast_dw.fact_order_goods1(
order_id string, – 订单id
goods_cat_3d_id string, – 商品三级分类id
shop_id string, – 店铺id
payment_id string, – 订单支付方式
goods_num bigint, – 商品数量
pay_money double, – 订单明细金额
paytime string – 订单时间
)
partitioned by (dt string)
STORED AS PARQUET;

–支付方式,0:未知;1:支付宝,2:微信;3、现金;4、其他

– 2. 拉宽订单明细事实表

insert overwrite table itcast_dw.fact_order_goods1 partition(dt=‘20190908’)
select
t1.orderid as order_id,
t3.goodscatid as goods_cat_3d_id,
t3.shopid as shop_id,
t1.paytype as payment_id,
t2.goodsnum as goods_num,
t2.payprice as pay_money,
t1.paytime as paytime
from
(select orderid, paytype, paytime from itcast_ods.itcast_orders where dt=‘20190908’) t1 – 订单表数据
left join
(select orderid, goodsid, goodsnum, payprice from itcast_ods.itcast_order_goods where dt=‘20190908’) t2 – 订单明细数
on t1.orderid = t2.orderid
left join
(select goodsid, shopid, goodscatid from itcast_dw.dim_goods where dw_end_date = ‘9999-12-31’) t3 – 商品数量
on t2.goodsid = t3.goodsid;

– 测试数据

select * from itcast_dw.fact_order_goods1 limit 5;

指标计算

– 指标统计
– 创建 ads 层结果表
create table if not exists itcast_ads.ads_trade_order(
area_type string, – 区域范围:区域类型(全国、大区、城市)
region_name string, – 区域名称
city_name string, – 城市名称
category_type string, --分类类型(一级、二级)
category_1st_name string, – 一级分类名称
category_2d_name string, – 二级分类名称
payment_name string, – 支付方式(所有、微信、支付宝、…)
total_count bigint, – 订单数量
total_goods_num bigint, – 商品数量
total_money double – 支付金额
)
partitioned by (dt string)
row format delimited fields terminated by ‘\001’ stored as TEXTFILE;

5.1、新交易详情表(tmp_order_goods)
订单表(fact_orders)与订单明细表详情(fact_order_goods)进行关联,组成新交易详情表(tmp_order_goods), 在原交易详情表基础上增加交易类型

参考代码:

DROP TABLE IF EXISTS itcast_dw.tmp_order_goods;
CREATE TABLE itcast_dw.tmp_order_goods(
ogid bigint,
orderid bigint,
goodsnum bigint,
goodsprice double,
goodsid bigint,
paytype tinyint)
PARTITIONED BY (dt string)
STORED AS PARQUET;

INSERT OVERWRITE TABLE itcast_dw.tmp_order_goods PARTITION (dt=‘20190908’)
SELECT
og.ogid, --订单明细表id
og.orderid,–订单id
og.goodsnum,–商品数量
og.goodsprice,–商品单价
og.goodsid,–商品id
orders.paytype --支付方式
FROM
(SELECT orderid,paytype FROM itcast_dw.fact_orders WHERE dt=‘20190908’ ) orders
LEFT JOIN
(SELECT ogid,orderid,goodsnum,goodsprice,goodsid FROM itcast_dw.fact_order_goods WHERE dt=‘20190908’ ) og
ON orders.orderid=og.orderid;

– 验证结果

SELECT * FROM itcast_dw.tmp_order_goods WHERE dt=‘20190908’ LIMIT 10;

5.2、新交易门店表(tmp_order_goods_shop)
新订单明细详情(tmp_order_goods)与商品表(dim_goods)、店铺表(dim_shops)进行关联,组成新交易门店表(tmp_order_goods_shop),在新订单交易详情基础上,增加门店相关信息与商品信息。
2.1 创建 tmp_order_goods_shop表
2.2 导入数据
关联 dim_goods 表
关联 dim_shops 表
参考代码:

– 表创建

DROP TABLE IF EXISTS itcast_dw.tmp_order_goods_shop;
CREATE TABLE itcast_dw.tmp_order_goods_shop(
ogid bigint,
orderid bigint,
shopid bigint,
goodsCatId bigint,
cityid bigint,
goodsnum bigint,
goodsprice double,
goodsid bigint,
paytype tinyint)
PARTITIONED BY (dt string)
STORED AS PARQUET;

– 插入数据

INSERT OVERWRITE TABLE itcast_dw.tmp_order_goods_shop PARTITION (dt=‘20190908’)
SELECT
tmp.ogid,
tmp.orderid,
goods.shopid,
goods.goodscatId,
shops.areaid,
tmp.goodsnum,
tmp.goodsprice,
tmp.goodsid,
tmp.paytype
FROM
(SELECT ogid,orderid,goodsnum,goodsprice,goodsid,paytype FROM itcast_dw.tmp_order_goods WHERE dt=‘20190908’) tmp
LEFT JOIN
(SELECT goodsid,shopid,goodsCatId FROM itcast_dw.dim_goods WHERE dw_end_date = ‘9999-12-31’ ) goods ON goods.goodsid=tmp.goodsid
LEFT JOIN
(SELECT shopid,areaid FROM itcast_dw.dim_shops WHERE dt=‘20190908’) shops ON shops.shopid=goods.shopid;

– 数据验证

SELECT * FROM itcast_dw.tmp_order_goods_shop LIMIT 10;

5.3、新交易信息宽表(tmp_order_goods_cat_org)(依赖2.4)
新交易门店表(tmp_order_goods_shop)与商品分类表和组织架构表进行关联,组成新交易信息宽表(tmp_order_goods_cat_org),在新交易门店表基础上增加
3.1 创建新交易门店表tmp_order_goods_cat_org
3.2 编写SQL连接 dim_goods_cats 的一级分类
3.2 编写SQL连接 dim_goods_cats 的二级分类
3.3 编写SQL连接 dim_goods_cats 的三级分类
3.4 编写SQL连接dim_org的销售部门(orgType=2)
商品分类信息与区域维度信息

– 创建表

DROP TABLE IF EXISTS itcast_dw.tmp_order_goods_cat_org;
CREATE TABLE itcast_dw.tmp_order_goods_cat_org(
ogid bigint,
orderid bigint,
shopid bigint,
firstcat bigint,
secondcat bigint,
thirdcat bigint,
cityid bigint,
regionid bigint,
goodsnum bigint,
goodsprice double,
goodsid bigint,
paytype tinyint)
PARTITIONED BY (dt string)
STORED AS PARQUET;

– 插入数据
INSERT OVERWRITE TABLE itcast_dw.tmp_order_goods_cat_org PARTITION (dt=‘20190908’)
SELECT
tmp.ogid,
tmp.orderid,
tmp.shopid,
scats.parentId AS firstcat,
tcats.parentId AS secondcat,
tmp.goodsCatId AS thirdcat,
tmp.cityid,
org.parentid AS regionId,
tmp.goodsnum,
tmp.goodsprice,
tmp.goodsid,
tmp.paytype
FROM
(SELECT ogid,orderid,shopid,goodsCatId,cityid,goodsnum,goodsprice,goodsid,paytype FROM itcast_dw.tmp_order_goods_shop WHERE dt=‘20190908’ ) tmp
LEFT JOIN (SELECT orgid,parentid FROM itcast_dw.dim_org WHERE dt=‘20190908’ AND orgtype=2 ) org ON org.orgid=tmp.cityid
LEFT JOIN (SELECT catId,parentId FROM itcast_dw.dim_goods_cats WHERE dt=‘20190908’ AND catlevel=3 ) tcats ON tcats.catId=tmp.goodsCatId
LEFT JOIN (SELECT catId,parentId FROM itcast_dw.dim_goods_cats WHERE dt=‘20190908’ AND catlevel=2 ) scats ON scats.catId=tcats.parentId;

– 验证结果

SELECT * FROM itcast_dw.tmp_order_goods_cat_org LIMIT 10;

2.6 指标计算汇总计算
到目前为止,新交易信息宽表(tmp_order_goods_cat_org)已经包含:
区域维度数据
商品分类维度数据。
根据需求,需要依据这两个维度进行汇总。最终在业务系统中展示如下:
公司高管拥有查询所有数据的权限,省份不选择时,看到的为全国范围内的数据,如果指定省份(本次开发的系统为大区)时,看到的为指定省份数据,如果指定某个城市,则看到的是指定城市的数据,同理商品分类维度类似推算。
目前新交易信息宽表(tmp_order_goods_cat_org)输入如下:

由于区域维度为分级维度,分为全国、大区、城市三级。通常情况下,我们会计算出城市维度,然后对城市维度数据进行汇总计算得出大区维度和全国维度数据,实际上,由于一个订单,由于会有多个商品,这些商品属于不同的商店,这些商店又属于不同的区域,故不能简单累加计算。

根据此订单信息分析,orderid为532的订单,实际上仅为一个订单,该订单共计3件商品,分别属于不同的商店,这些商店分属北京、石家庄、上海城市。
在区域维度计算时。精确到城市维度数据计算应该如下:

精确到大区维度数据计算应该如下:

精确到全国维度数据计算时结果数据应该如下:

全国、无商品分类维度的交易信息
由于需求中需要列出支付宝支付笔数,微信交易笔数与总交易笔数,根据数据信息,支付共计分为支付宝交易、微信交易、现金交易、其他交易和未知交易类型(支付方式,0:未知;1:支付宝,2:微信;3、现金;4、其他)
故每个维度的数据计算时,除按照支付类型进行分组获取各种支付类型支付的数据外,还要获取不分任何类型的数据。
需求:
1、获取全国、无商品分类维度的分交易类型数据
2、获取全国、无商品分类维度的不分交易类型的数据
注意事项:
第一个INSERT导入数据到数据集市,使用overwrite,第二个则应该使用into
计算如下:
– 获取全国、无商品分类维度的分交易类型数据

INSERT OVERWRITE TABLE itcast_ads.ads_trade_order PARTITION (dt=‘20190908’)
SELECT
‘0’, --全国 大区–x 城市—y
‘9999’,
‘0’, --无商品分类 和 各个级别 1 2 3
‘9999’,
paytype,
count(distinct orderid),
sum(goodsnum*goodsprice)
FROM itcast_dw.tmp_order_goods_cat_org WHERE dt=‘20190908’
GROUP BY paytype;

– 获取全国、无商品分类维度的不分交易类型的数据

INSERT into TABLE itcast_ads.ads_trade_order PARTITION (dt=‘20190908’)
SELECT
‘0’,
‘9999’,
‘0’,
‘9999’,
‘9’, – 不分交易类型
count(distinct orderid),
sum(goodsprice*goodsprice)
FROM itcast_dw.tmp_order_goods_cat_org WHERE dt=‘20190908’;


– 测试

select * from itcast_ads.ads_trade_order limit 5;

全国、一级商品分类维度交易信息
需求:
1、获取全国、一级商品分类维度的分交易类型数据
2、获取全国、一级商品分类维度的不分交易类型数据

– 获取全国、一级商品分类维度的分交易类型数据
INSERT into TABLE itcast_ads.ads_trade_order PARTITION (dt=‘20190908’)
SELECT
‘0’,
‘9999’,
‘1’,
firstcat,
paytype,
count(distinct orderid),
sum(goodsprice*goodsprice)
FROM itcast_dw.tmp_order_goods_cat_org WHERE dt=‘20190908’
GROUP BY paytype,firstcat;

– 获取全国、一级商品分类维度的不分交易类型数据

INSERT into TABLE itcast_ads.ads_trade_order PARTITION (dt=‘20190908’)
SELECT
‘0’,
‘9999’,
‘1’,
firstcat,
‘9’,
count(distinct orderid),
sum(goodsprice*goodsprice)
FROM itcast_dw.tmp_order_goods_cat_org WHERE dt=‘20190908’
GROUP BY firstcat;

– 测试

select * from itcast_ads.ads_trade_orderlimit 5;

全国、二级商品分类维度交易信息
需求:
1、获取全国、二级商品分类维度的分交易类型数据
2、获取全国、二级商品不分类维度的分交易类型数据
– 获取全国、二级商品分类维度的分交易类型数据

INSERT into TABLE itcast_ads.ads_trade_order PARTITION (dt=‘20190908’)
SELECT
‘0’,
‘9999’,
‘2’,
secondcat,
paytype,
count(distinct orderid),
sum(goodsprice*goodsprice)
FROM itcast_dw.tmp_order_goods_cat_org WHERE dt=‘20190908’
GROUP BY paytype,secondcat;

– 获取全国、二级商品不分类维度的不分交易类型数据

INSERT into TABLE itcast_ads.ads_trade_order PARTITION (dt=‘20190908’)
SELECT
‘0’,
‘9999’,
‘2’,
secondcat,
‘9’,
count(distinct orderid),
sum(goodsprice*goodsprice)
FROM itcast_dw.tmp_order_goods_cat_org WHERE dt=‘20190908’
GROUP BY secondcat;

大区、无商品分类维度的交易信息
需求:
1、获取大区、无商品分类维度的分交易类型数据
2、获取大区、不分商品不分类维度的不分交易类型数据
参考代码:
– 获取大区、无商品分类维度的分交易类型数据

INSERT into TABLE itcast_ads.ads_trade_order PARTITION (dt=‘20190908’)
SELECT
‘1’, – 1 大区
regionid,
‘0’,
‘9999’,
paytype,
count(distinct orderid),
sum(goodsprice*goodsprice)
FROM itcast_dw.tmp_order_goods_cat_org WHERE dt=‘20190908’
GROUP BY paytype,regionid;

– 获取大区、不分商品不分类维度的不分交易类型数据

INSERT into TABLE itcast_ads.ads_trade_order PARTITION (dt=‘20190908’)
SELECT
‘0’,
‘9999’,
‘1’,
regionid,
‘9’,
count(distinct orderid),
sum(goodsprice*goodsprice)
FROM itcast_dw.tmp_order_goods_cat_org WHERE dt=‘20190908’
GROUP BY regionid;

大区、一级商品分类维度交易信息
1、获取大区、一级商品分类维度的分交易类型数据
2、获取大区、一级商品分类维度的不分交易类型数据
参考代码:
– 获取大区、一级商品分类维度的分交易类型数据

INSERT into TABLE itcast_ads.ads_trade_order PARTITION (dt=‘20190908’)
SELECT
‘1’,
regionid,
‘1’,
firstcat,
paytype,
count(distinct orderid),
sum(goodsprice*goodsprice)
FROM itcast_dw.tmp_order_goods_cat_org WHERE dt=‘20190908’
GROUP BY paytype,firstcat,regionid;

– 获取大区、一级商品分类维度的不分交易类型数据

INSERT into TABLE itcast_ads.ads_trade_order PARTITION (dt=‘20190908’)
SELECT
‘1’,
regionid,
‘1’,
firstcat,
‘9’,
count(distinct orderid),
sum(goodsprice*goodsprice)
FROM itcast_dw.tmp_order_goods_cat_org WHERE dt=‘20190908’
GROUP BY firstcat,regionid;

大区、二级商品分类维度交易信息
1、获取大区、二级商品分类维度的分交易类型数据
2、获取大区、二级商品分类维度的不分交易类型数据
参考代码:
– 获取大区、二级商品分类维度的分交易类型数据

INSERT into TABLE itcast_ads.ads_trade_order PARTITION (dt=‘20190908’)
SELECT
‘1’,
regionid,
‘2’,
secondcat,
paytype,
count(distinct orderid),
sum(goodsprice*goodsprice)
FROM itcast_dw.tmp_order_goods_cat_org WHERE dt=‘20190908’
GROUP BY paytype,secondcat,regionid;

– 获取大区、二级商品分类维度的不分交易类型数据

INSERT into TABLE itcast_ads.ads_trade_order PARTITION (dt=‘20190908’)
SELECT
‘1’,
regionid,
‘2’,
secondcat,
‘9’,
count(distinct orderid),
sum(goodsprice*goodsprice)
FROM itcast_dw.tmp_order_goods_cat_org WHERE dt=‘20190908’
GROUP BY secondcat,regionid;

城市、无商品分类维度交易信息
1、 获取城市、无商品分类维度的分交易类型数据
2、获取城市、无商品分类维度的不分交易类型数据
参考代码:
– 获取城市、无商品分类维度的分交易类型数据

INSERT into TABLE itcast_ads.ads_trade_order PARTITION (dt=‘20190908’)
SELECT
‘2’,
cityid,
‘0’,
‘9999’,
paytype,
count(distinct orderid),
sum(goodsprice*goodsprice)
FROM itcast_dw.tmp_order_goods_cat_org WHERE dt=‘20190908’
GROUP BY paytype,cityid;

– 获取城市、无商品分类维度的不分交易类型数据

INSERT into TABLE itcast_ads.ads_trade_order PARTITION (dt=‘20190908’)
SELECT
‘2’,
cityid,
‘0’,
‘9999’,
‘9’,
count(distinct orderid),
sum(goodsprice*goodsprice)
FROM itcast_dw.tmp_order_goods_cat_org WHERE dt=‘20190908’
GROUP BY cityid;

城市、一级商品分类维度交易信息
1、获取城市、一级商品分类维度的不分交易类型数据
2、获取城市、一级商品分类维度的分交易类型数据
参考代码:
– 获取城市、一级商品分类维度的分交易类型数据

INSERT into TABLE itcast_ads.ads_trade_order PARTITION (dt=‘20190908’)
SELECT
‘2’,
cityid,
‘1’,
firstcat,
paytype,
count(distinct orderid),
sum(goodsprice*goodsprice)
FROM itcast_dw.tmp_order_goods_cat_org WHERE dt=‘20190908’
GROUP BY paytype,firstcat,cityid;

– 获取城市、一级商品分类维度的不分交易类型数据

INSERT into TABLE itcast_ads.ads_trade_order PARTITION (dt=‘20190908’)
SELECT
‘2’,
cityid,
‘1’,
firstcat,
‘9’,
count(distinct orderid),
sum(goodsprice*goodsprice)
FROM itcast_dw.tmp_order_goods_cat_org WHERE dt=‘20190908’
GROUP BY firstcat,cityid;

城市、二级商品分类维度交易信息
1、获取城市、二级商品分类维度的不分交易类型数据
2、获取城市、二级商品分类维度的分交易类型数据
参考代码:
– 获取城市、二级商品分类维度的分交易类型数据

INSERT into TABLE itcast_ads.ads_trade_order PARTITION (dt=‘20190908’)
SELECT
‘2’, – 2 代表城市
cityid,
‘2’,
secondcat,
paytype,
count(distinct orderid),
sum(goodsprice*goodsprice)
FROM itcast_dw.tmp_order_goods_cat_org WHERE dt=‘20190908’
GROUP BY paytype, secondcat,cityid;

– 获取城市、二级商品分类维度的不分交易类型数据

INSERT into TABLE itcast_ads.ads_trade_order PARTITION (dt=‘20190908’)
SELECT
‘2’,
cityid,
‘2’,
secondcat,
‘9’,
count(distinct orderid),
sum(goodsprice*goodsprice)
FROM itcast_dw.tmp_order_goods_cat_org WHERE dt=‘20190908’
GROUP BY secondcat,cityid;

千亿数仓第四章(指标计算_订单分析地域、分类维度分析业务开发)相关推荐

  1. 千亿数仓第三章(数仓理论_项目环境初始化)

    项目环境初始化 3.1 Hive分层说明 分库存放 ods层 dw层 ads层 命名规则 ods层表与原始数据库表名称相同 dw层表 ofact_前缀表示事实表 odim_前缀表示维度表 ...

  2. 数仓(四)数据仓库分层

    上一节我们了解了数仓中常见的两大建模体系:关系建模和维度建模,并论述了维度建模的4个步骤. 数仓(二)关系建模和维度建模 数仓(三)简析阿里.美团.网易.恒丰银行.马蜂窝5家数仓分层架构 其实数仓建模 ...

  3. 大数据实战【千亿级数仓】阶段三

    写在前面: 博主是一名大数据的初学者,昵称来源于<爱丽丝梦游仙境>中的Alice和自己的昵称.作为一名互联网小白,写博客一方面是为了记录自己的学习历程,一方面是希望能够帮助到很多和自己一样 ...

  4. 大数据实战【千亿级数仓】阶段二

    写在前面: 博主是一名大数据的初学者,昵称来源于<爱丽丝梦游仙境>中的Alice和自己的昵称.作为一名互联网小白,写博客一方面是为了记录自己的学习历程,一方面是希望能够帮助到很多和自己一样 ...

  5. 数仓面试|四个在工作后才知道的SQL密技

    SQL是大数据从业者的必备技能,大部分的大数据技术框架也都提供了SQL的解决方案.可以说SQL是一种经久不衰.历久弥新的编程语言.尤其是在数仓领域,使用SQL更是家常便饭.本文会分享四个在面试和工作中 ...

  6. 系列 | 漫谈数仓第四篇NO.4 『数据应用』(BIOLAP)

    点击上方蓝色字体,置顶/星标哦 目前10000+人已关注加入我们 本文目录CONTENTS ☞ 01.可视化BI工具 [ 开源BI,商业BI,传统BI ] ☞ 02.OLAP科普 [ ROLAP  M ...

  7. 本地数仓项目(四)—— 即席查询

    1 背景 本文描述本地数仓项目即席查询相关内容,主要涉及即席查询工具包括Presto.Druid.Kylin. 本文基于文章<本地数据仓库项目(一) -- 本地数仓搭建详细流程> 和< ...

  8. 千亿级数仓项目(二)

    许久不见.咱们接着之前的来讲,你应该按我说的把kettle给学了一遍了吧?没学的话请赶紧去学,否则后面你也看不懂. 咱们今天从数仓理论开始讲! 数据仓库维度模型设计 1 维度建模基本概念 维度模型是数 ...

  9. ▼ 系列 | 漫谈数仓第四篇NO.4 『BI选型』

    大数据时代商业智能(BI)和数据可视化诉求更为强烈,淘宝大屏更是风靡全球!数据可视化是大数据『最后一公里』,BI唤醒沉睡的数据. 传统型BI力求大而全的统一综合型报表和分析平台,侧重传统式报表开发,俨 ...

  10. 【正点原子STM32连载】第四章 STM32初体验 摘自【正点原子】MiniPro STM32H750 开发指南_V1.1

    1)实验平台:正点原子MiniPro H750开发板 2)平台购买地址:https://detail.tmall.com/item.htm?id=677017430560 3)全套实验源码+手册+视频 ...

最新文章

  1. 疫情过后,对医疗AI行业带来的机遇
  2. JQuery Easy Ui 可装载组合框 - ComboBox
  3. 英语听力里面的religion words
  4. Android sdk Drow9patch使用
  5. 全球最囧的爱情测试.....
  6. mysql中列的默认值
  7. 卷积与反卷积、步长(stride)与重叠(overlap)及 output 的大小
  8. 2017百度之星资格赛:1002. 度度熊的王国战略
  9. 利用Ajax实现DataGrid无刷新分页(AjaxGrid)【转】
  10. 苹果mac应用程序卸载软件:App Uninstaller
  11. 【水果识别】基于matlab GUI自助水果超市【含Matlab源码 594期】
  12. 51单片机程序下载失败原因排查
  13. python灰色预测模型_GM(1,n)(灰色模型代码)
  14. comsol matlab script,comsol script
  15. 电感式传感器的原理大白话
  16. 华南理工计算机电路基础试题,2017年华南理工大学计算机电路基础.doc
  17. mdio phy(bcm5482)访问
  18. DAO是什么?——为什么有人试图购买美国宪法?
  19. 2.2 STM32 RAM溢出分析(KEIL在Build的时候提示Error:L6406E:No space in execution)
  20. 平板电脑软件测试招聘,【华为工资】软件测试工程师待遇-看准网

热门文章

  1. AcWing 兔子与兔子
  2. android 资源id 闪退,【报Bug】android闪退,勾选Push消息推送自定义基座后 获取oaid,vaid,aaid, app闪退...
  3. matlab 植被指数,基于matlab的MOD13A2-NDVI的植被指数重建-SG滤波与质量控制文件
  4. Origin 2022安装教程(附下载链接)
  5. Stochastic Pooling简单理解
  6. RANSAC算法详解+Python实现
  7. 基于PHP的超市库存管理系统
  8. android dagger2 单例,Dagger2进阶-单例
  9. 检测mysql表更新吗,知网查重系统的数据库是多久更新一次?
  10. 宿舍管理系统简单的增删改查