2订单分析地域、分类维度分析业务开发
总结需求1:
ads数据都来源于dw, DW层数据都来源于ods。 ads一张表存储了18个需求的所有数据
2.1 需求分析
集团总公司分为很多的分公司(销售事业部)
为了公司的经营需要,公司需要定期检查各个分公司的经营指标完成情况,运营部门提出数据分析需求:
交易金额
交易笔数
微信交易笔数
支付宝交易笔数
维度如下:
商品分类
行政区域
要求:最终可以根据不同大区、不同城市、不能分类级别查询交易数据,也就是要求支持不同维度的组合查询。
需求:
获取全国、无商品分类维度的分交易类型数据
获取全国、无商品分类维度的不分交易类型的数据
获取全国、一级商品分类维度的分交易类型数据
获取全国、一级商品分类维度的不分交易类型数据
获取全国、二级商品分类维度的分交易类型数据
获取全国、二级商品不分类维度的分交易类型数据
获取大区、无商品分类维度的分交易类型数据
获取大区、无商品不分类维度的不分交易类型数据
获取大区、一级商品分类维度的分交易类型数据
获取大区、一级商品分类维度的不分交易类型数据
获取大区、二级商品分类维度的分交易类型数据
获取大区、二级商品分类维度的不分交易类型数据
获取城市、无商品分类维度的分交易类型数据
获取城市、无商品分类维度的不分交易类型数据
获取城市、一级商品分类维度的不分交易类型数据
获取城市、一级商品分类维度的分交易类型数据
获取城市、二级商品分类维度的不分交易类型数据
获取城市、二级商品分类维度的分交易类型数据
根据需求整理出用到的表
最终的流程图:
2.2 创建 ads 层数据表
– 创建ads(数据集市层)订单分析表
DROP TABLE IF EXISTSitcast_ads
.ads_trade_order
;
CREATE TABLEitcast_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 EXISTSitcast_dw
.fact_orders
;
CREATE TABLEitcast_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 EXISTSitcast_dw
.dim_goods_cats
;
CREATE TABLEitcast_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 TABLEitcast_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 EXISTSitcast_dw
.dim_shops
;
CREATE TABLEitcast_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
FROMitcast_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
FROMitcast_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
FROMitcast_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
FROMitcast_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 * fromitcast_ods
.itcast_goods_cats
WHERE cat_level=2 and dt=‘20190908’ limit 5;
select * fromitcast_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
FROMitcast_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
FROMitcast_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 EXISTSitcast_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;
– 测试数据
2、商品分类维度数据拉宽
dim_goods_cat
商品表维度数据拉宽
参考代码:
– 表创建
DROP TABLE IF EXISTSitcast_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;
– 测试数据
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;
– 测试数据
指标计算
– 指标统计
– 创建 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 TABLEitcast_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 TABLEitcast_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 TABLEitcast_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;
– 数据验证
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 TABLEitcast_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 TABLEitcast_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;
– 验证结果
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)
FROMitcast_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)
FROMitcast_dw
.tmp_order_goods_cat_org
WHERE dt=‘20190908’;
– 测试
全国、一级商品分类维度交易信息
需求:
1、获取全国、一级商品分类维度的分交易类型数据
2、获取全国、一级商品分类维度的不分交易类型数据
– 获取全国、一级商品分类维度的分交易类型数据
INSERT into TABLEitcast_ads
.ads_trade_order
PARTITION (dt=‘20190908’)
SELECT
‘0’,
‘9999’,
‘1’,
firstcat,
paytype,
count(distinct orderid),
sum(goodsprice*goodsprice)
FROMitcast_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)
FROMitcast_dw
.tmp_order_goods_cat_org
WHERE dt=‘20190908’
GROUP BY firstcat;
– 测试
全国、二级商品分类维度交易信息
需求:
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)
FROMitcast_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)
FROMitcast_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)
FROMitcast_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)
FROMitcast_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)
FROMitcast_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)
FROMitcast_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)
FROMitcast_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)
FROMitcast_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)
FROMitcast_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)
FROMitcast_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)
FROMitcast_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)
FROMitcast_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)
FROMitcast_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)
FROMitcast_dw
.tmp_order_goods_cat_org
WHERE dt=‘20190908’
GROUP BY secondcat,cityid;