Compare commits
17 Commits
67a5b0c78b
...
main
Author | SHA1 | Date | |
---|---|---|---|
![]() |
00a51ac679 | ||
![]() |
bff7559882 | ||
![]() |
b395436b1e | ||
34745d3991 | |||
19862dbf4a | |||
6cb53ada93 | |||
5c9320ca38 | |||
![]() |
45b09ffc43 | ||
bede12aec0 | |||
1ecd0b508b | |||
532574c836 | |||
0574e30a52 | |||
2815f094cf | |||
445bfc3a95 | |||
c3896caaf1 | |||
![]() |
2b80c0c441 | ||
![]() |
93fdf41096 |
431
SQL.sql
431
SQL.sql
@@ -1,50 +1,104 @@
|
||||
<<<<<<< HEAD
|
||||
-- 线上店铺年度销售金额、订单数量、退款金额、退款订单数、订单均价
|
||||
SELECT
|
||||
sales.store_name as '店铺名称',
|
||||
year(sales.order_date) AS '年份',
|
||||
round(sum(sales.order_settle_amt),2) as '销售金额',
|
||||
COUNT(sales.platform_order_no) +
|
||||
SUM(LENGTH(sales.platform_order_no) - LENGTH(REPLACE(sales.platform_order_no, ',', ''))) as '订单数量',
|
||||
round(sum(change.special_barcode_amt),2) as '退款金额',
|
||||
count(refund.platform_order_no) as '退款订单数',
|
||||
round(sum(sales.order_settle_amt)/count(sales.platform_order_no),2) as '订单均价'
|
||||
FROM
|
||||
dwd_trade_hkaudit_ecommerce_sale_mt sales
|
||||
left join dwd_trade_hkaudit_ecommerce_sale_return_mt refund
|
||||
on sales.platform_order_no = refund.platform_order_no
|
||||
left join dwd_trade_hkaudit_ecommerce_sale_change_mt change
|
||||
on refund.platform_order_no = change.platform_order_no
|
||||
WHERE
|
||||
sales.order_date >= '2022-01-01 00:00:00'
|
||||
AND sales.order_date <'2025-07-31 00:00:00'
|
||||
GROUP BY
|
||||
sales.store_name, year(sales.order_date)
|
||||
s.店铺编码,
|
||||
s.年份,
|
||||
ROUND(s.销售金额,2) AS '销售金额',
|
||||
s.订单数量,
|
||||
r.退款金额,
|
||||
r.退款订单数,
|
||||
ROUND(s.销售金额/s.订单数量,2) AS '订单均价'
|
||||
FROM(
|
||||
SELECT
|
||||
store_code AS '店铺编码',
|
||||
YEAR(order_date) AS '年份',
|
||||
SUM(order_settle_amt) AS '销售金额',
|
||||
-- 针对并单号情况,统计总行数加逗号个数得到总订单数量
|
||||
COUNT(platform_order_no) +
|
||||
SUM(LENGTH(platform_order_no) - LENGTH(REPLACE(platform_order_no, ',', ''))) AS '订单数量'
|
||||
FROM
|
||||
dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE
|
||||
order_date >= '2022-01-01 00:00:00'
|
||||
AND order_date <'2025-07-01 00:00:00'
|
||||
GROUP BY
|
||||
store_code,YEAR(order_date)
|
||||
) s --销售
|
||||
LEFT JOIN(
|
||||
SELECT
|
||||
YEAR(order_date) AS '年份',
|
||||
store_code AS '店铺编码',
|
||||
ROUND(SUM(refund.amount)+SUM(change.amount),2) AS '退款金额',
|
||||
COUNT(refund.platform_order_no) AS '退款订单数'
|
||||
FROM(
|
||||
SELECT
|
||||
-- 将拆分后的单个订单号作为分组和查询的键
|
||||
single_order_id AS single_order_no,
|
||||
MIN(store_code) AS store_code,
|
||||
MIN(order_date) AS order_date
|
||||
FROM(
|
||||
SELECT
|
||||
store_code,
|
||||
platform_order_no,
|
||||
order_date,
|
||||
splitByChar(',', platform_order_no) AS order_id_array
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE
|
||||
order_date >= '2022-01-01 00:00:00'
|
||||
AND order_date <'2025-07-01 00:00:00'
|
||||
)
|
||||
-- 使用arrayJoin将数组中的每个元素展开为一行
|
||||
ARRAY JOIN order_id_array AS single_order_id
|
||||
GROUP BY single_order_no
|
||||
) sales
|
||||
LEFT JOIN(
|
||||
SELECT
|
||||
platform_order_no,
|
||||
SUM(return_goods_amt)
|
||||
FROM
|
||||
dwd_trade_hkaudit_ecommerce_sale_return_mt
|
||||
GROUP BY
|
||||
platform_order_no
|
||||
) refund
|
||||
ON sales.platform_order_no = refund.platform_order_no
|
||||
LEFT JOIN(
|
||||
SELECT
|
||||
platform_order_no,
|
||||
SUM(special_barcode_amt) AS amount
|
||||
FROM
|
||||
dwd_trade_hkaudit_ecommerce_sale_change_mt
|
||||
) change
|
||||
ON sales.platform_order_no = change.platform_order_no
|
||||
WHERE
|
||||
refund.platform_order_no IS NOT NULL
|
||||
GROUP BY
|
||||
store_code,YEAR(order_date)
|
||||
) r -- 退款
|
||||
ON s.店铺编码 = r.店铺编码 AND s.年份 = r.年份
|
||||
ORDER BY
|
||||
sales.store_name ASC, 年份 ASC
|
||||
年份 ASC, 销售金额 DESC;
|
||||
|
||||
|
||||
-- 线下店铺年度销售金额、订单数量、退款金额、退款订单数、订单均价
|
||||
SELECT
|
||||
store_name as '店铺名称',
|
||||
store_code as '店铺编码',
|
||||
YEAR(pay_date) as '年份',
|
||||
round(sum(CASE WHEN pay_amt > 0 THEN pay_amt ELSE 0 END), 2) as '销售金额',
|
||||
count(CASE WHEN pay_amt > 0 THEN receipt_no ELSE NULL END) as '订单数量',
|
||||
round(abs(sum(CASE WHEN pay_amt < 0 THEN pay_amt ELSE 0 END)), 2) as '退款金额',
|
||||
count(CASE WHEN pay_amt < 0 THEN receipt_no ELSE NULL END) as '退款订单数'
|
||||
FROM
|
||||
FROM
|
||||
dwd_trade_hkaudit_shop_receipt_pay_mt
|
||||
WHERE
|
||||
WHERE
|
||||
pay_date >= '2022-01-01 00:00:00'
|
||||
AND pay_date < '2025-07-01 00:00:00'
|
||||
GROUP BY
|
||||
store_name, YEAR(pay_date)
|
||||
ORDER BY
|
||||
store_name ASC, 年份 ASC;
|
||||
GROUP BY
|
||||
store_code, YEAR(pay_date)
|
||||
ORDER BY
|
||||
store_code ASC, 年份 ASC;
|
||||
|
||||
-- 线上店铺月度销售金额
|
||||
SELECT
|
||||
store_name as '店铺名称',
|
||||
store_code as '店铺编码',
|
||||
YEAR(order_date) as '年份',
|
||||
month(order_date) as '月份',
|
||||
round(sum(order_settle_amt),2) as '销售金额'
|
||||
@@ -54,13 +108,13 @@ WHERE
|
||||
order_date >= '2022-01-01 00:00:00'
|
||||
AND order_date <'2025-07-01 00:00:00'
|
||||
GROUP BY
|
||||
store_name,年份,月份
|
||||
store_code,年份,月份
|
||||
order BY
|
||||
store_name,年份 asc,月份 asc
|
||||
store_code,年份 asc,月份 asc
|
||||
|
||||
-- 线下店铺月度销售金额
|
||||
SELECT
|
||||
store_name as '店铺名称',
|
||||
store_code as '店铺编码',
|
||||
year(pay_date) as '年份',
|
||||
month(pay_date) as '月份',
|
||||
round(sum(CASE WHEN pay_amt > 0 THEN pay_amt ELSE 0 END), 2) as '销售金额'
|
||||
@@ -70,15 +124,15 @@ WHERE
|
||||
pay_date >= '2022-01-01 00:00:00'
|
||||
AND pay_date <'2025-07-01 00:00:00'
|
||||
GROUP BY
|
||||
store_name,year(pay_date),month(pay_date)
|
||||
store_code,year(pay_date),month(pay_date)
|
||||
order BY
|
||||
store_name,年份 asc,月份 asc
|
||||
store_code,年份 asc,月份 asc
|
||||
|
||||
-- 线上每年各产品数量、产品销售金额
|
||||
SELECT
|
||||
goods_barcode,
|
||||
year(order_date) as '年份',
|
||||
sum(good_qty) as '产品数量',
|
||||
sum(goods_qty) as '产品数量',
|
||||
order_settle_amt as '销售金额'
|
||||
FROM
|
||||
dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
@@ -91,35 +145,47 @@ order BY
|
||||
goods_barcode,年份;
|
||||
|
||||
-- 线下每年各产品数量、产品销售金额
|
||||
-- (订单号重复,根据订单号groupby后失去产品信息,小票支付表仅有订单号可关联,如何计算?)
|
||||
-- 根据商品标价比例计算实际金额
|
||||
SELECT
|
||||
YEAR(b.pay_time) AS '年份',
|
||||
a.goods_barcode AS '商品条码',
|
||||
SUM(a.qty) AS '产品数量',
|
||||
ROUND(SUM(b.total_real_amt * (a.goods_amt) / b.price_tag), 2) AS '销售金额'
|
||||
FROM (
|
||||
SELECT
|
||||
platform_order_no,
|
||||
goods_barcode,
|
||||
goods_amt
|
||||
price,
|
||||
qty
|
||||
FROM dwd_trade_hkaudit_shop_receipt_mt
|
||||
) a
|
||||
INNER JOIN(
|
||||
SELECT
|
||||
platform_order_no,
|
||||
SUM(goods_amt) as price_tag
|
||||
FROM dwd_trade_hkaudit_shop_receipt_mt
|
||||
GROUP BY platform_order_no
|
||||
) b
|
||||
ON a.platform_order_no = b.platform_order_no
|
||||
INNER JOIN (
|
||||
SELECT
|
||||
platform_order_no,
|
||||
SUM(pay_amt) as total_real_amt
|
||||
FROM dwd_trade_hkaudit_shop_receipt_pay_mt
|
||||
GROUP BY platform_order_no
|
||||
) c ON
|
||||
a.platform_order_no = c.platform_order_no
|
||||
GROUP BY
|
||||
YEAR(b.pay_time), a.goods_barcode
|
||||
ORDER BY
|
||||
年份, 销售金额 DESC;
|
||||
|
||||
-- FROM(
|
||||
-- SELECT
|
||||
-- platform_order_no,
|
||||
-- max(pay_date) as pay_time,
|
||||
-- sum(pay_amt) as amount
|
||||
-- FROM
|
||||
-- dwd_trade_hkaudit_shop_receipt_pay_mt
|
||||
-- WHERE
|
||||
-- pay_date >='2022-01-01 00:00:00'
|
||||
-- AND pay_date <'2025-07-01 00:00:00'
|
||||
-- GROUP BY
|
||||
-- platform_order_no
|
||||
-- ) pay
|
||||
-- left join(
|
||||
-- SELECT
|
||||
-- platform_order_no,
|
||||
-- count(platform_order_no) as num
|
||||
-- FROM
|
||||
-- dwd_trade_hkaudit_shop_receipt_mt
|
||||
-- GROUP BY
|
||||
-- platform_order_no
|
||||
-- ) order_num
|
||||
-- on
|
||||
-- pay.platform_order_no = order_num.platform_order_no
|
||||
|
||||
-- 线上每年前五店铺金额分布
|
||||
SELECT
|
||||
store_name as '店铺名称',
|
||||
store_code as '店铺编码',
|
||||
sum(order_settle_amt) as '销售金额'
|
||||
FROM
|
||||
dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
@@ -127,14 +193,14 @@ WHERE
|
||||
order_date >= '2022-01-01 00:00:00'
|
||||
AND order_date < '2023-01-01 00:00:00'
|
||||
GROUP BY
|
||||
store_name
|
||||
store_code
|
||||
order BY
|
||||
sum(order_settle_amt) desc
|
||||
LIMIT 5
|
||||
|
||||
-- 线下每年前五店铺金额分布
|
||||
SELECT
|
||||
store_name as '店铺名称',
|
||||
store_code as '店铺编码',
|
||||
round(sum(CASE WHEN pay_amt > 0 THEN pay_amt ELSE 0 END), 2) as '销售金额'
|
||||
FROM
|
||||
dwd_trade_hkaudit_shop_receipt_pay_mt
|
||||
@@ -142,9 +208,9 @@ WHERE
|
||||
pay_date >= '2022-01-01 00:00:00'
|
||||
AND pay_date <'2023-01-01 00:00:00'
|
||||
GROUP BY
|
||||
店铺名称
|
||||
店铺编码
|
||||
order BY
|
||||
线上店铺前五金额分布 desc
|
||||
销售金额 desc
|
||||
LIMIT 5
|
||||
|
||||
-- 线上每年各省份销售金额、订单数量
|
||||
@@ -163,37 +229,63 @@ GROUP BY
|
||||
|
||||
-- 线下每年各店铺所在省份销售金额、订单数量
|
||||
-- (如何确认店铺所在省份?)
|
||||
|
||||
SELECT
|
||||
store_code as '店铺编码',
|
||||
round(sum(CASE WHEN pay_amt > 0 THEN pay_amt ELSE 0 END), 2) as '销售金额'
|
||||
FROM
|
||||
dwd_trade_hkaudit_shop_receipt_pay_mt
|
||||
WHERE
|
||||
pay_date >= '2022-01-01 00:00:00'
|
||||
AND pay_date <'2023-01-01 00:00:00'
|
||||
GROUP BY
|
||||
店铺编码
|
||||
order BY
|
||||
销售金额 desc
|
||||
|
||||
-- 线上每年单笔订单金额分布
|
||||
-- (并单如何考虑单笔金额?)
|
||||
-- 单个订单号使用订单均摊金额,并单号均分金额
|
||||
SELECT
|
||||
YEAR(order_date) AS '年份',
|
||||
YEAR(a.order_date) AS '年份',
|
||||
a.money_area AS '单笔订单金额',
|
||||
count(a.platform_order_no) as '订单数量',
|
||||
ROUND(sum(a.order_settle_amt),2) AS '销售金额'
|
||||
count(a.split_item) as '订单数量',
|
||||
ROUND(sum(a.split_amount),2) AS '销售金额'
|
||||
FROM(
|
||||
SELECT
|
||||
order_settle_amt,
|
||||
platform_order_no,
|
||||
single.split_amount,
|
||||
single.split_item,
|
||||
single.order_date,
|
||||
CASE
|
||||
WHEN order_settle_amt >0 AND order_settle_amt <10 THEN '0-10'
|
||||
WHEN order_settle_amt >=10 AND order_settle_amt <50 THEN '10-50'
|
||||
WHEN order_settle_amt >=50 AND order_settle_amt <100 THEN '50-100'
|
||||
WHEN order_settle_amt >=100 AND order_settle_amt <500 THEN '100-500'
|
||||
WHEN order_settle_amt >=500 AND order_settle_amt <1000 THEN '500-1000'
|
||||
WHEN order_settle_amt >=1000 AND order_settle_amt <5000 THEN '1000-5000'
|
||||
WHEN order_settle_amt >=5000 AND order_settle_amt <10000 THEN '5000-10000'
|
||||
WHEN order_settle_amt >=10000 THEN '10000及以上'
|
||||
WHEN single.split_amount >0 AND single.split_amount <10 THEN '0-10'
|
||||
WHEN single.split_amount >=10 AND single.split_amount <50 THEN '10-50'
|
||||
WHEN single.split_amount >=50 AND single.split_amount <100 THEN '50-100'
|
||||
WHEN single.split_amount >=100 AND single.split_amount <500 THEN '100-500'
|
||||
WHEN single.split_amount >=500 AND single.split_amount <1000 THEN '500-1000'
|
||||
WHEN single.split_amount >=1000 AND single.split_amount <5000 THEN '1000-5000'
|
||||
WHEN single.split_amount >=5000 AND single.split_amount <10000 THEN '5000-10000'
|
||||
WHEN single.split_amount >=10000 THEN '10000及以上'
|
||||
END AS money_area
|
||||
FROM
|
||||
dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE
|
||||
order_date >='2022-01-01 00:00:00'
|
||||
AND order_date <'2025-07-01 00:00:00'
|
||||
) a
|
||||
FROM(
|
||||
SELECT
|
||||
order_date,
|
||||
split_item,
|
||||
goods_amt / length(split_array) as split_amount -- 金额均分
|
||||
FROM (
|
||||
SELECT
|
||||
order_date,
|
||||
goods_amt,
|
||||
splitByChar(',', platform_order_no) as split_array
|
||||
FROM
|
||||
dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE
|
||||
order_date >='2022-01-01 00:00:00'
|
||||
AND order_date <'2025-07-01 00:00:00'
|
||||
) single
|
||||
ARRAY JOIN split_array AS split_item
|
||||
)
|
||||
) a
|
||||
GROUP BY
|
||||
a.money_area
|
||||
YEAR(a.order_date),a.money_area
|
||||
ORDER BY
|
||||
年份,
|
||||
CASE a.money_area
|
||||
@@ -249,7 +341,18 @@ ORDER BY
|
||||
END;
|
||||
|
||||
-- 线上每年同一个收货地址销售金额、订单数量(需考虑脱敏情况)
|
||||
|
||||
SELECT
|
||||
地址
|
||||
round(sum(sales.order_settle_amt),2) as '销售金额',
|
||||
COUNT(sales.platform_order_no) +
|
||||
SUM(LENGTH(sales.platform_order_no) - LENGTH(REPLACE(sales.platform_order_no, ',', ''))) as '订单数量'
|
||||
FROM
|
||||
dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE
|
||||
order_date >='2022-01-01 00:00:00'
|
||||
AND order_date <'2025-07-01 00:00:00'
|
||||
GROUP BY
|
||||
地址
|
||||
|
||||
-- 线上每年各天和各小时订单数和销售金额
|
||||
-- 各天
|
||||
@@ -296,7 +399,7 @@ FROM(
|
||||
SELECT
|
||||
platform_order_no,
|
||||
max(pay_date) as pay_time,
|
||||
sum(pay_amt) as amount
|
||||
round(sum(CASE WHEN pay_amt > 0 THEN pay_amt ELSE 0 END), 2) as amount
|
||||
FROM
|
||||
dwd_trade_hkaudit_shop_receipt_pay_mt
|
||||
WHERE
|
||||
@@ -331,7 +434,7 @@ FROM (
|
||||
SELECT
|
||||
platform_order_no,
|
||||
MAX(pay_date) as pay_time,
|
||||
SUM(pay_amt) as amount
|
||||
sum(CASE WHEN pay_amt > 0 THEN pay_amt ELSE 0 END) as amount
|
||||
FROM
|
||||
dwd_trade_hkaudit_shop_receipt_pay_mt
|
||||
WHERE
|
||||
@@ -358,7 +461,7 @@ ORDER BY
|
||||
|
||||
-- 线上每年大促期间店铺销售金额、订单数量
|
||||
SELECT
|
||||
store_name as '店铺名称',
|
||||
store_code as '店铺编码',
|
||||
YEAR(order_date) AS '年份',
|
||||
CASE
|
||||
WHEN (MONTH(order_date) = 6 AND DAY(order_date) BETWEEN 15 AND 21) THEN '父亲节'
|
||||
@@ -377,8 +480,8 @@ WHERE order_date >= '2022-01-01 00:00:00'
|
||||
(MONTH(order_date) = 6 AND DAY(order_date) BETWEEN 10 AND 20) OR -- 618
|
||||
(MONTH(order_date) = 11 AND DAY(order_date) BETWEEN 1 AND 15) -- 双11
|
||||
)
|
||||
GROUP BY store_name, YEAR(order_date), 大促类型
|
||||
ORDER BY store_name ASC, 年份 ASC,
|
||||
GROUP BY store_code, YEAR(order_date), 大促类型
|
||||
ORDER BY store_code ASC, 年份 ASC,
|
||||
CASE
|
||||
WHEN '大促类型' = '父亲节' THEN 1
|
||||
WHEN '大促类型' = '618' THEN 2
|
||||
@@ -386,19 +489,155 @@ ORDER BY store_name ASC, 年份 ASC,
|
||||
END;
|
||||
|
||||
-- 线下每年大促期间店铺销售金额、订单数量
|
||||
|
||||
SELECT
|
||||
year(pay_time) as '年份',
|
||||
pay.store as '店铺编码',
|
||||
CASE
|
||||
WHEN (MONTH(pay.pay_time) = 6 AND DAY(pay.pay_time) BETWEEN 15 AND 21) THEN '父亲节'
|
||||
WHEN (MONTH(pay.pay_time) = 6 AND DAY(pay.pay_time) BETWEEN 10 AND 20) THEN '618'
|
||||
WHEN (MONTH(pay.pay_time) = 11 AND DAY(pay.pay_time) BETWEEN 1 AND 15) THEN '双11'
|
||||
ELSE '其他'
|
||||
END as '大促类型',
|
||||
ROUND(SUM(pay.amount), 2) as '销售金额',
|
||||
sum(order_num.num) as '订单数量'
|
||||
FROM(
|
||||
SELECT
|
||||
platform_order_no,
|
||||
max(store_code) as store,
|
||||
max(pay_date) as pay_time,
|
||||
sum(CASE WHEN pay_amt > 0 THEN pay_amt ELSE 0 END) as amount
|
||||
FROM
|
||||
dwd_trade_hkaudit_shop_receipt_pay_mt
|
||||
WHERE
|
||||
pay_date >='2022-01-01 00:00:00'
|
||||
AND pay_date <'2025-07-01 00:00:00'
|
||||
AND (
|
||||
(MONTH(pay_date) = 6 AND DAY(pay_date) BETWEEN 15 AND 21) OR -- 父亲节
|
||||
(MONTH(pay_date) = 6 AND DAY(pay_date) BETWEEN 10 AND 20) OR -- 618
|
||||
(MONTH(pay_date) = 11 AND DAY(pay_date) BETWEEN 1 AND 15) -- 双11
|
||||
)
|
||||
GROUP BY
|
||||
platform_order_no
|
||||
) pay
|
||||
left join(
|
||||
SELECT
|
||||
platform_order_no,
|
||||
count(platform_order_no) as num
|
||||
FROM
|
||||
dwd_trade_hkaudit_shop_receipt_mt
|
||||
GROUP BY
|
||||
platform_order_no
|
||||
) order_num
|
||||
on
|
||||
pay.platform_order_no = order_num.platform_order_no
|
||||
GROUP BY store_code, YEAR(order_date), 大促类型
|
||||
ORDER BY store_code, 年份,
|
||||
CASE
|
||||
WHEN '大促类型' = '父亲节' THEN 1
|
||||
WHEN '大促类型' = '618' THEN 2
|
||||
WHEN '大促类型' = '双11' THEN 3
|
||||
END;
|
||||
|
||||
|
||||
-- 线上每年订单下单和发货间隔的销售金额、订单数量分布
|
||||
-- (并单如何考虑下单时间?)
|
||||
-- 视为同一时间下单
|
||||
SELECT
|
||||
CASE timestampdiff(day,deliver_date,order_date)
|
||||
WHEN 0 THEN '当天'
|
||||
WHEN 1 THEN '1天'
|
||||
WHEN 2 THEN '2天'
|
||||
WHEN 3 THEN '3天'
|
||||
WHEN 4 THEN '4天'
|
||||
ELSE '5天及以上'
|
||||
END AS '发货间隔',
|
||||
SUM(order_settle_amt) AS '销售金额',
|
||||
COUNT(platform_order_no) +
|
||||
SUM(LENGTH(platform_order_no) - LENGTH(REPLACE(platform_order_no, ',', ''))) AS '订单数量'
|
||||
FROM
|
||||
dwd_trade_hkaudit_ecommerce_sale_mt sales
|
||||
WHERE
|
||||
order_date >= '2022-01-01 00:00:00'
|
||||
AND order_date < '2025-07-31 00:00:00'
|
||||
GROUP BY
|
||||
发货间隔
|
||||
ORDER BY
|
||||
CASE 发货间隔
|
||||
WHEN '当天' THEN 1
|
||||
WHEN '1天' THEN 2
|
||||
WHEN '2天' THEN 3
|
||||
WHEN '3天' THEN 4
|
||||
WHEN '4天' THEN 5
|
||||
WHEN '5天及以上' THEN 6
|
||||
END;
|
||||
|
||||
|
||||
-- 线上每年各物流承运商销售金额、订单数量
|
||||
|
||||
SELECT
|
||||
year(sales.order_date) AS '年份',
|
||||
carrier as '物流承运商',
|
||||
round(sum(sales.order_settle_amt),2) as '销售金额',
|
||||
COUNT(sales.platform_order_no) +
|
||||
SUM(LENGTH(sales.platform_order_no) - LENGTH(REPLACE(sales.platform_order_no, ',', ''))) as '订单数量'
|
||||
FROM
|
||||
dwd_trade_hkaudit_ecommerce_sale_mt sales
|
||||
WHERE
|
||||
order_date >= '2022-01-01 00:00:00'
|
||||
AND order_date < '2025-07-31 00:00:00'
|
||||
GROUP BY
|
||||
year(sales.order_date), carrier
|
||||
order BY 年份, carrier;
|
||||
|
||||
-- 线上每年退款大于原销售的差异金额、订单数量
|
||||
SELECT
|
||||
store_code AS '店铺编码',
|
||||
YEAR(order_date) AS '年份',
|
||||
ROUND(SUM(excess_refund), 2) AS '差异金额',
|
||||
COUNT(*) AS '订单数量'
|
||||
FROM (
|
||||
SELECT
|
||||
s.store_code,
|
||||
s.order_date,
|
||||
s.order_settle_amt AS sale_amt,
|
||||
COALESCE(r.return_amt, 0) + COALESCE(c.change_amt, 0) AS refund_amt,
|
||||
CASE
|
||||
WHEN (COALESCE(r.return_amt, 0) + COALESCE(c.change_amt, 0)) > ABS(s.order_settle_amt)
|
||||
THEN (COALESCE(r.return_amt, 0) + COALESCE(c.change_amt, 0)) - ABS(s.order_settle_amt)
|
||||
ELSE 0
|
||||
END AS excess_refund
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt s
|
||||
LEFT JOIN (
|
||||
SELECT platform_order_no, SUM(return_goods_amt) AS return_amt
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_return_mt
|
||||
GROUP BY platform_order_no
|
||||
) r ON s.platform_order_no = r.platform_order_no
|
||||
LEFT JOIN (
|
||||
SELECT platform_order_no, SUM(special_barcode_amt) AS change_amt
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_change_mt
|
||||
GROUP BY platform_order_no
|
||||
) c ON s.platform_order_no = c.platform_order_no
|
||||
WHERE (r.return_amt IS NOT NULL OR c.change_amt IS NOT NULL)
|
||||
AND s.order_date >= '2022-01-01 00:00:00'
|
||||
AND s.order_date < '2025-07-01 00:00:00'
|
||||
) excess_data
|
||||
WHERE excess_refund > 0
|
||||
GROUP BY store_code, YEAR(order_date)
|
||||
ORDER BY 年份, 超额退款总金额 DESC;
|
||||
|
||||
|
||||
-- 线下每年退款大于原销售的差异金额、订单数量
|
||||
=======
|
||||
SELECT * FROM a;113333sss
|
||||
>>>>>>> bcf2f3cd58c4c0fbd7ef580d305440999d743a5d
|
||||
SELECT
|
||||
YEAR(pay_time) AS '年份',
|
||||
SUM(total_refund - total_sale) AS '差异金额',
|
||||
COUNT(*) AS '订单数量'
|
||||
FROM (
|
||||
SELECT
|
||||
receipt_no,
|
||||
SUM(CASE WHEN pay_amt > 0 THEN pay_amt ELSE 0 END) AS total_sale,
|
||||
SUM(CASE WHEN pay_amt < 0 THEN ABS(pay_amt) ELSE 0 END) AS total_refund,
|
||||
MAX(pay_date) AS pay_time
|
||||
FROM dwd_trade_hkaudit_shop_receipt_pay_mt
|
||||
GROUP BY receipt_no
|
||||
HAVING total_refund > total_sale
|
||||
)
|
||||
GROUP BY YEAR(pay_time);
|
Binary file not shown.
Binary file not shown.
541
数据分析/v3/数据.sql
Normal file
541
数据分析/v3/数据.sql
Normal file
File diff suppressed because one or more lines are too long
952
数据分析/v3/正式-处理.sql
Normal file
952
数据分析/v3/正式-处理.sql
Normal file
File diff suppressed because one or more lines are too long
1486
数据分析/v3/正式-查询-下单时间(算换货) - 副本.sql
Normal file
1486
数据分析/v3/正式-查询-下单时间(算换货) - 副本.sql
Normal file
File diff suppressed because it is too large
Load Diff
869
数据分析/v3/正式-查询-下单时间-old(不算换货).sql
Normal file
869
数据分析/v3/正式-查询-下单时间-old(不算换货).sql
Normal file
@@ -0,0 +1,869 @@
|
||||
-- 1.1线上各店铺每年度销售金额、订单数量、订单均价
|
||||
-- 数量和单价只能计算有订单的,账单的不能算
|
||||
SELECT
|
||||
SUBSTR(t1.order_time, 1, 4) AS "年份",
|
||||
t1.store_code AS "店铺编码",
|
||||
MAX(t1.store_name) AS "店铺名称",
|
||||
SUM(t1.order_amt) + SUM(t2.order_freight_amt) AS "销售金额(元)(包含运费)",
|
||||
SUM(t2.order_freight_amt) AS "运费金额(元)",
|
||||
COUNT(t1.platform_order_no) AS "订单数量",
|
||||
ROUND((SUM(t1.order_amt) + SUM(t2.order_freight_amt)) / COUNT(t1.platform_order_no), 2) AS "订单均价(元)"
|
||||
FROM (SELECT store_code, platform_order_no, MAX(store_name) AS store_name, MIN(order_time) AS order_time, SUM(goods_amt) AS order_amt
|
||||
FROM custom_online_sale_order_local
|
||||
GROUP BY store_code, platform_order_no
|
||||
) t1 LEFT JOIN (
|
||||
-- EC算运费
|
||||
SELECT store_code, platform_order_no, SUM(order_freight_amt_t) AS order_freight_amt
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
system_order_no,
|
||||
platform_order_no,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE source_system IN ('EC_HIS_NEW', 'EC_HIS2') AND order_freight_amt <> 0
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
) GROUP BY store_code, platform_order_no
|
||||
) t2 ON t1.store_code = t2.store_code AND t1.platform_order_no = t2.platform_order_no
|
||||
WHERE t1.order_time >= '2022-01-01' AND t1.order_time <= '2025-06-30'
|
||||
GROUP BY SUBSTR(t1.order_time, 1, 4), t1.store_code
|
||||
ORDER BY SUBSTR(t1.order_time, 1, 4), (SUM(t1.order_amt) + SUM(t2.order_freight_amt)) DESC;
|
||||
|
||||
-- 账单店铺金额
|
||||
SELECT
|
||||
SUBSTR(order_time, 1, 4) AS "年份",
|
||||
store_code AS "店铺编码",
|
||||
MAX(store_name) AS "店铺名称",
|
||||
SUM(goods_amt) AS "销售金额(元)"
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt >= 0
|
||||
GROUP BY SUBSTR(order_time, 1, 4), store_code
|
||||
ORDER BY SUBSTR(order_time, 1, 4), SUM(goods_amt) DESC;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 1.2线上各店铺每年度净销售金额
|
||||
SELECT
|
||||
SUBSTR(t1.order_time, 1, 4) AS "年份",
|
||||
t1.store_code AS "店铺编码",
|
||||
MAX(t1.store_name) AS "店铺名称",
|
||||
SUM(t1.order_amt) AS "销售金额(元)",
|
||||
SUM(t2.order_freight_amt) AS "运费金额(元)",
|
||||
SUM(t3.order_return_goods_amt) AS "退货金额(元)",
|
||||
SUM(t4.order_return_freight_amt) AS "退货运费金额(元)",
|
||||
SUM(t5.order_change_amount) AS "发货调整金额(元)",
|
||||
SUM(t1.order_amt) + SUM(t2.order_freight_amt) + SUM(t3.order_return_goods_amt)
|
||||
+ SUM(t4.order_return_freight_amt) + SUM(t5.order_change_amount) AS "净销售金额(元)"
|
||||
FROM (SELECT store_code, platform_order_no, MAX(store_name) AS store_name, MIN(order_time) AS order_time, SUM(goods_amt) AS order_amt
|
||||
FROM custom_online_sale_order_local
|
||||
GROUP BY store_code, platform_order_no
|
||||
) t1 LEFT JOIN (
|
||||
-- EC算运费
|
||||
SELECT store_code, platform_order_no, SUM(order_freight_amt_t) AS order_freight_amt
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
system_order_no,
|
||||
platform_order_no,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE source_system IN ('EC_HIS_NEW', 'EC_HIS2') AND order_freight_amt <> 0
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
) GROUP BY store_code, platform_order_no
|
||||
) t2 ON t1.store_code = t2.store_code AND t1.platform_order_no = t2.platform_order_no
|
||||
LEFT JOIN (
|
||||
SELECT store_code, platform_order_no, SUM(return_goods_amt) AS order_return_goods_amt
|
||||
FROM custom_online_sale_return_local
|
||||
GROUP BY store_code, platform_order_no
|
||||
) t3 ON t1.store_code = t3.store_code AND t1.platform_order_no = t3.platform_order_no
|
||||
LEFT JOIN (
|
||||
SELECT store_code, platform_order_no, SUM(return_freight_amt_t) AS order_return_freight_amt
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
system_order_no,
|
||||
platform_order_no,
|
||||
MAX(return_freight_amt) AS return_freight_amt_t
|
||||
FROM custom_online_sale_return_local
|
||||
WHERE source_system IN ('EC_HIS_NEW', 'EC_HIS2') AND return_freight_amt <> 0
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
) GROUP BY store_code, platform_order_no
|
||||
) t4 ON t1.store_code = t4.store_code AND t1.platform_order_no = t4.platform_order_no
|
||||
LEFT JOIN (
|
||||
SELECT store_code, platform_order_no, SUM(special_barcode_amt) AS order_change_amount
|
||||
FROM custom_online_sale_change_local
|
||||
GROUP BY store_code, platform_order_no
|
||||
) t5 ON t1.store_code = t5.store_code AND t1.platform_order_no = t5.platform_order_no
|
||||
WHERE t1.order_time >= '2022-01-01' AND t1.order_time <= '2025-06-30'
|
||||
GROUP BY SUBSTR(t1.order_time, 1, 4), t1.store_code
|
||||
ORDER BY SUBSTR(t1.order_time, 1, 4), (SUM(t1.order_amt) + SUM(t2.order_freight_amt) + SUM(t3.order_return_goods_amt)
|
||||
+ SUM(t4.order_return_freight_amt) + SUM(t5.order_change_amount)) DESC;
|
||||
|
||||
-- 账单店铺金额
|
||||
SELECT
|
||||
t1.perYear AS "年份",
|
||||
t1.store_code AS "店铺编码",
|
||||
t1.store_name AS "店铺名称",
|
||||
t1.sale_amount AS "销售金额(元)",
|
||||
t2.return_amount AS "退货金额(元)",
|
||||
t1.sale_amount + t2.return_amount AS "净销售金额(元)"
|
||||
FROM (SELECT
|
||||
SUBSTR(order_time, 1, 4) AS perYear,
|
||||
store_code,
|
||||
MAX(store_name) AS store_name,
|
||||
SUM(goods_amt) AS sale_amount
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt >= 0
|
||||
GROUP BY SUBSTR(order_time, 1, 4), store_code
|
||||
) t1 LEFT JOIN (
|
||||
SELECT
|
||||
SUBSTR(order_time, 1, 4) AS perYear,
|
||||
store_code,
|
||||
SUM(goods_amt) AS return_amount
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt < 0
|
||||
GROUP BY SUBSTR(order_time, 1, 4), store_code
|
||||
) t2 ON t1.perYear = t2.perYear AND t1.store_code = t2.store_code
|
||||
ORDER BY t1.perYear, (t1.sale_amount + t2.return_amount) DESC;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 1.3线上各店铺每年月度销售金额
|
||||
SELECT
|
||||
SUBSTR(t1.order_time, 1, 4) AS "年份",
|
||||
SUBSTR(t1.order_time, 6, 2) AS "月份",
|
||||
t1.store_code AS "店铺编码",
|
||||
MAX(t1.store_name) AS "店铺名称",
|
||||
SUM(t1.order_amt) + SUM(t2.order_freight_amt) AS "销售金额(元)(包含运费)",
|
||||
SUM(t2.order_freight_amt) AS "运费金额(元)",
|
||||
COUNT(t1.platform_order_no) AS "订单数量",
|
||||
ROUND((SUM(t1.order_amt) + SUM(t2.order_freight_amt)) / COUNT(t1.platform_order_no), 2) AS "订单均价(元)"
|
||||
FROM (SELECT store_code, platform_order_no, MAX(store_name) AS store_name, MIN(order_time) AS order_time, SUM(goods_amt) AS order_amt
|
||||
FROM custom_online_sale_order_local
|
||||
GROUP BY store_code, platform_order_no
|
||||
) t1 LEFT JOIN (
|
||||
-- EC算运费
|
||||
SELECT store_code, platform_order_no, SUM(order_freight_amt_t) AS order_freight_amt
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
system_order_no,
|
||||
platform_order_no,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE source_system IN ('EC_HIS_NEW', 'EC_HIS2') AND order_freight_amt <> 0
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
) GROUP BY store_code, platform_order_no
|
||||
) t2 ON t1.store_code = t2.store_code AND t1.platform_order_no = t2.platform_order_no
|
||||
WHERE t1.order_time >= '2022-01-01' AND t1.order_time <= '2025-06-30'
|
||||
GROUP BY SUBSTR(t1.order_time, 1, 4), SUBSTR(t1.order_time, 6, 2), t1.store_code
|
||||
ORDER BY SUBSTR(t1.order_time, 1, 4), t1.store_code, SUBSTR(t1.order_time, 6, 2);
|
||||
|
||||
-- 账单店铺金额
|
||||
SELECT
|
||||
SUBSTR(order_time, 1, 4) AS "年份",
|
||||
SUBSTR(order_time, 6, 2) AS "月份",
|
||||
store_code AS "店铺编码",
|
||||
MAX(store_name) AS "店铺名称",
|
||||
SUM(goods_amt) AS "销售金额(元)"
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt >= 0
|
||||
GROUP BY SUBSTR(order_time, 1, 4), SUBSTR(order_time, 6, 2), store_code
|
||||
ORDER BY SUBSTR(order_time, 1, 4), store_code, SUBSTR(order_time, 6, 2);
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 1.4线上每年前五店铺金额分布
|
||||
|
||||
-- xxxxxxxxxxxxxxxxx
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 1.5线上每年各产品数量、产品销售金额
|
||||
SELECT *
|
||||
FROM custom_online_sale_order_local;
|
||||
|
||||
SELECT * FROM dim_hkaudit_goods_mt WHERE barcode IN (
|
||||
SELECT barcode
|
||||
FROM dim_hkaudit_goods_mt GROUP BY barcode HAVING COUNT(DISTINCT goods_code) > 1)
|
||||
ORDER By barcode ;
|
||||
|
||||
SELECT * FROM dim_hkaudit_goods_mt dhgm WHERE barcode = 'VRDBJ41159A01001A11';
|
||||
SELECT * FROM dim_hkaudit_goods_mt WHERE goods_code IN (SELECT goods_barcode FROM custom_online_sale_order_local);
|
||||
|
||||
|
||||
SELECT * FROM dim_hkaudit_goods_mt a left join custom_online_sale_order_local b on a.barcode = b.goods_barcode ;
|
||||
|
||||
SELECT COUNT() FROM dim_hkaudit_goods_mt;
|
||||
SELECT COUNT() FROM dim_hkaudit_goods_mt_local;
|
||||
|
||||
-- 不关联商品名称(每个表单独算)
|
||||
SELECT
|
||||
SUBSTR(order_time, 1, 4) AS "年份",
|
||||
goods_barcode AS "商品条码",
|
||||
SUM(goods_qty) AS "商品数量",
|
||||
SUM(goods_amt) AS "商品销售金额(元)"
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE order_time >= '2022-01-01' AND order_time <= '2025-06-30'
|
||||
GROUP BY SUBSTR(order_time, 1, 4), goods_barcode
|
||||
ORDER BY SUBSTR(order_time, 1, 4), SUM(goods_amt) DESC;
|
||||
|
||||
-- 账单店铺金额
|
||||
SELECT
|
||||
SUBSTR(order_time, 1, 4) AS "年份",
|
||||
goods_barcode AS "商品条码",
|
||||
SUM(goods_qty) AS "商品数量",
|
||||
SUM(goods_amt) AS "商品销售金额(元)"
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt >= 0
|
||||
GROUP BY SUBSTR(order_time, 1, 4), goods_barcode
|
||||
ORDER BY SUBSTR(order_time, 1, 4), SUM(goods_amt) DESC;
|
||||
|
||||
----------------------
|
||||
-- 集群同步有问题
|
||||
--SELECT
|
||||
-- SUBSTR(t1.order_time, 1, 4) AS "年份",
|
||||
-- t1.goods_barcode AS "商品条码",
|
||||
-- MAX(t2.goods_names) AS "商品名称(多个合并)",
|
||||
-- SUM(t1.goods_qty) AS "商品数量",
|
||||
-- SUM(t1.goods_amt) AS "商品销售金额(元)"
|
||||
--FROM custom_online_sale_order_local t1
|
||||
--LEFT JOIN (SELECT barcode, arrayStringConcat(groupArray(goods_desc), ',') AS goods_names FROM dim_hkaudit_goods_mt GROUP BY barcode
|
||||
--) t2 ON t1.goods_barcode = t2.barcode
|
||||
--WHERE t1.order_time >= '2022-01-01' AND t1.order_time <= '2025-06-30'
|
||||
--GROUP BY SUBSTR(t1.order_time, 1, 4), t1.goods_barcode
|
||||
--ORDER BY SUBSTR(t1.order_time, 1, 4), SUM(t1.goods_amt) DESC;
|
||||
|
||||
----------------------
|
||||
-- 不关联商品名称(两表合并算)
|
||||
SELECT
|
||||
perYear AS "年份",
|
||||
goods_barcode AS "商品条码",
|
||||
SUM(goods_qty) AS "商品数量",
|
||||
SUM(goods_amt) AS "商品销售金额(元)"
|
||||
FROM (SELECT
|
||||
SUBSTR(order_time, 1, 4) AS perYear,
|
||||
goods_barcode,
|
||||
goods_qty,
|
||||
goods_amt
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE order_time >= '2022-01-01' AND order_time <= '2025-06-30'
|
||||
UNION ALL
|
||||
SELECT
|
||||
SUBSTR(order_time, 1, 4) AS perYear,
|
||||
goods_barcode,
|
||||
goods_qty,
|
||||
goods_amt
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt >= 0
|
||||
)
|
||||
GROUP BY perYear, goods_barcode
|
||||
ORDER BY perYear, SUM(goods_amt) DESC;
|
||||
|
||||
-- 集群同步有问题
|
||||
--SELECT
|
||||
-- t1.perYear AS "年份",
|
||||
-- t1.goods_barcode AS "商品条码",
|
||||
-- MAX(t2.goods_names) AS "商品名称(多个合并)",
|
||||
-- SUM(t1.goods_qty) AS "商品数量",
|
||||
-- SUM(t1.goods_amt) AS "商品销售金额(元)"
|
||||
--FROM (SELECT
|
||||
-- SUBSTR(order_time, 1, 4) AS perYear,
|
||||
-- goods_barcode,
|
||||
-- goods_qty,
|
||||
-- goods_amt
|
||||
-- FROM custom_online_sale_order_local
|
||||
-- WHERE order_time >= '2022-01-01' AND order_time <= '2025-06-30'
|
||||
-- UNION ALL
|
||||
-- SELECT
|
||||
-- SUBSTR(order_time, 1, 4) AS perYear,
|
||||
-- goods_barcode,
|
||||
-- goods_qty,
|
||||
-- goods_amt
|
||||
-- FROM custom_online_sale_bill_local
|
||||
-- WHERE goods_amt >= 0
|
||||
--) t1 LEFT JOIN (
|
||||
-- SELECT barcode, arrayStringConcat(groupArray(goods_desc), ',') AS goods_names FROM dim_hkaudit_goods_mt GROUP BY barcode
|
||||
--) t2 ON t1.goods_barcode = t2.barcode
|
||||
--GROUP BY t1.perYear, t1.goods_barcode
|
||||
--ORDER BY t1.perYear, SUM(t1.goods_amt) DESC;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 2.1线上每年各省份销售金额、订单数量及其占比
|
||||
-- 1234791条平台订单没有省份
|
||||
SELECT source_system, COUNT(DISTINCT platform_order_no) FROM custom_online_sale_order_local WHERE province = '' GROUP BY source_system;
|
||||
-- 只能计算有订单的,账单的不能算(没有省份)
|
||||
-- 考虑店铺单号重复问题 非换货单有946单重复,加上换货单有1229条重复
|
||||
-- 忽略省份为空的平台订单
|
||||
SELECT
|
||||
a.perYear AS "年份",
|
||||
a.province_t AS "省份",
|
||||
a.sale_amount + a.freight_amount AS "销售金额(元)(包含运费)",
|
||||
a.freight_amount AS "运费金额(元)",
|
||||
a.order_count AS "订单数量", -- 不去重,多个店铺算多单
|
||||
b.all_order_count AS "订单总数量",
|
||||
ROUND((a.sale_amount + a.freight_amount) / b.all_order_count, 2) AS "订单占比"
|
||||
FROM (SELECT
|
||||
SUBSTR(t1.order_time, 1, 4) AS perYear,
|
||||
t1.province_t,
|
||||
SUM(t1.order_amt) AS sale_amount,
|
||||
SUM(t2.order_freight_amt) AS freight_amount,
|
||||
COUNT(t1.platform_order_no) AS order_count -- 不去重,多个店铺算多单
|
||||
FROM
|
||||
(SELECT store_code, platform_order_no, MIN(order_time) AS order_time, SUM(goods_amt) AS order_amt, MAX(province) AS province_t
|
||||
FROM custom_online_sale_order_local
|
||||
GROUP BY store_code, platform_order_no
|
||||
) t1 LEFT JOIN (
|
||||
-- EC算运费
|
||||
SELECT store_code, platform_order_no, SUM(order_freight_amt_t) AS order_freight_amt
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
system_order_no,
|
||||
platform_order_no,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE source_system IN ('EC_HIS_NEW', 'EC_HIS2') AND order_freight_amt <> 0
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
) GROUP BY store_code, platform_order_no
|
||||
) t2 ON t1.store_code = t2.store_code AND t1.platform_order_no = t2.platform_order_no
|
||||
WHERE t1.order_time >= '2022-01-01' AND t1.order_time <= '2025-06-30' AND province_t <> ''
|
||||
GROUP BY SUBSTR(t1.order_time, 1, 4), t1.province_t
|
||||
) a LEFT JOIN (SELECT SUBSTR(order_time, 1, 4) AS perYear, COUNT(platform_order_no) AS all_order_count
|
||||
FROM (SELECT store_code, platform_order_no, MIN(order_time) AS order_time, MAX(province) AS province_t
|
||||
FROM custom_online_sale_order_local
|
||||
GROUP BY store_code, platform_order_no)
|
||||
WHERE order_time >= '2022-01-01' AND order_time <= '2025-06-30' AND province_t <> ''
|
||||
GROUP BY SUBSTR(order_time, 1, 4)
|
||||
) b ON a.perYear = b.perYear
|
||||
ORDER BY a.perYear, (a.sale_amount + a.freight_amount) DESC;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 2.2线上每年各等级城市销售金额、订单数量及其占比
|
||||
-- 城市为空 -> 其他
|
||||
-- 省直辖县级行政区 -> 区域替换城市(其他区和空也直接换)
|
||||
-- 湖北省直辖县 -> 区域替换城市(其它区也直接换)
|
||||
-- 县 -> 省份替换城市
|
||||
-- 自治区直辖县级行政区划 -> 区域替换城市
|
||||
-- 省直辖县级行政区划 -> 区域替换城市(其他区和空也直接换)
|
||||
-- 新疆维吾尔自治区直辖县 -> 区域替换城市
|
||||
-- 维吾尔自治区 -> 区域替换城市
|
||||
-- 河南省直辖县 -> 区域替换城市
|
||||
-- 市辖区 -> 省份替换城市
|
||||
-- 广东 -> 区域替换城市
|
||||
-- 湖北 -> 区域替换城市
|
||||
SELECT city, COUNT() FROM custom_online_sale_order_local GROUP BY city;
|
||||
|
||||
SELECT DISTINCT region FROM custom_online_sale_order_local WHERE city = '省直辖县级行政区';
|
||||
SELECT * FROM custom_online_sale_order_local WHERE city = '省直辖县级行政区' AND region = '';
|
||||
SELECT * FROM custom_online_sale_order_local WHERE city = '省直辖县级行政区' AND region = '其它区';
|
||||
|
||||
SELECT DISTINCT region FROM custom_online_sale_order_local WHERE city = '湖北省直辖县';
|
||||
|
||||
SELECT DISTINCT province FROM custom_online_sale_order_local WHERE city = '县';
|
||||
|
||||
SELECT * FROM custom_online_sale_order_local WHERE city = '自治区直辖县级行政区划';
|
||||
|
||||
SELECT DISTINCT region FROM custom_online_sale_order_local WHERE city = '省直辖县级行政区划';
|
||||
SELECT * FROM custom_online_sale_order_local WHERE city = '省直辖县级行政区划' AND region = '';
|
||||
SELECT * FROM custom_online_sale_order_local WHERE city = '省直辖县级行政区划' AND region = '其它区';
|
||||
|
||||
SELECT * FROM custom_online_sale_order_local WHERE city = '新疆维吾尔自治区直辖县';
|
||||
|
||||
SELECT * FROM custom_online_sale_order_local WHERE city = '维吾尔自治区';
|
||||
|
||||
SELECT * FROM custom_online_sale_order_local WHERE city = '河南省直辖县';
|
||||
|
||||
SELECT * FROM custom_online_sale_order_local WHERE city = '市辖区';
|
||||
|
||||
SELECT * FROM custom_online_sale_order_local WHERE city = '广东';
|
||||
|
||||
SELECT * FROM custom_online_sale_order_local WHERE city = '湖北';
|
||||
|
||||
-- 1236382条平台订单没有城市
|
||||
SELECT source_system, COUNT(DISTINCT platform_order_no) FROM custom_online_sale_order_local WHERE city = '' GROUP BY source_system;
|
||||
-- 城市和等级关联到的只有5695单 需要手工调整
|
||||
SELECT DISTINCT city FROM custom_online_sale_order_local;
|
||||
-- 只能计算有订单的,账单的不能算(没有城市)
|
||||
-- 忽略城市为空的平台订单
|
||||
SELECT
|
||||
a.perYear AS "年份",
|
||||
a.city_grade,
|
||||
a.sale_amount + a.freight_amount AS "销售金额(元)(包含运费)",
|
||||
a.freight_amount AS "运费金额(元)",
|
||||
a.order_count AS "订单数量", -- 不去重,多个店铺算多单
|
||||
b.all_order_count AS "订单总数量",
|
||||
ROUND((a.sale_amount + a.freight_amount) / b.all_order_count, 2) AS "订单占比"
|
||||
FROM (SELECT
|
||||
SUBSTR(t1.order_time, 1, 4) AS perYear,
|
||||
t3.city_grade AS city_grade,
|
||||
SUM(t1.order_amt) AS sale_amount,
|
||||
SUM(t2.order_freight_amt) AS freight_amount,
|
||||
COUNT(t1.platform_order_no) AS order_count -- 不去重,多个店铺算多单
|
||||
FROM (SELECT store_code, platform_order_no, MIN(order_time) AS order_time, SUM(goods_amt) AS order_amt, MAX(TRIM(city)) AS city_t
|
||||
FROM custom_online_sale_order_local
|
||||
GROUP BY store_code, platform_order_no
|
||||
) t1 LEFT JOIN (
|
||||
-- EC算运费
|
||||
SELECT store_code, platform_order_no, SUM(order_freight_amt_t) AS order_freight_amt
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
system_order_no,
|
||||
platform_order_no,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE source_system IN ('EC_HIS_NEW', 'EC_HIS2') AND order_freight_amt <> 0
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
) GROUP BY store_code, platform_order_no
|
||||
) t2 ON t1.store_code = t2.store_code AND t1.platform_order_no = t2.platform_order_no
|
||||
LEFT JOIN custom_online_city_grade_local t3 ON t1.city_t = t3.city
|
||||
WHERE t1.order_time >= '2022-01-01' AND t1.order_time <= '2025-06-30' AND t3.city_grade <> ''
|
||||
GROUP BY SUBSTR(t1.order_time, 1, 4), t3.city_grade
|
||||
) a LEFT JOIN (SELECT SUBSTR(t1.order_time, 1, 4) AS perYear, COUNT(t1.platform_order_no) AS all_order_count
|
||||
FROM (SELECT store_code, platform_order_no, MIN(order_time) AS order_time, MAX(TRIM(city)) AS city_t
|
||||
FROM custom_online_sale_order_local
|
||||
GROUP BY store_code, platform_order_no) t1
|
||||
LEFT JOIN custom_online_city_grade_local t2 ON t1.city_t = t2.city
|
||||
WHERE t1.order_time >= '2022-01-01' AND t1.order_time <= '2025-06-30' AND t2.city_grade <> ''
|
||||
GROUP BY SUBSTR(t1.order_time, 1, 4)
|
||||
) b ON a.perYear = b.perYear
|
||||
ORDER BY a.perYear, (a.sale_amount + a.freight_amount) DESC;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 3.1线上每年单笔订单金额分布及其占比
|
||||
|
||||
-- xxxxxxxxxxxxxxxxx
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 3.2线上每年同一个收货地址的地址数量、销售金额、订单数量
|
||||
-- 100053条
|
||||
SELECT platform_order_no FROM custom_online_sale_order_local GROUP BY platform_order_no HAVING COUNT(DISTINCT consignee_add) > 1;
|
||||
SELECT * FROM custom_online_sale_order_local WHERE platform_order_no = '4920083542368856013A';
|
||||
-- SBZ换货没有标识 | 换货单或者手工单发货地址为明文,与平台是一个地址,但是平台属于密文,只取一个
|
||||
-- 1869294条平台订单没有收货地址,账单的都没有
|
||||
SELECT
|
||||
SUBSTR(t1.order_time, 1, 4) AS "年份",
|
||||
t1.order_addr AS "收货地址",
|
||||
SUM(t1.order_amt) + SUM(t2.order_freight_amt) AS "销售金额(元)(包含运费)",
|
||||
SUM(t2.order_freight_amt) AS "运费金额(元)",
|
||||
COUNT(t1.platform_order_no) AS "订单数量"
|
||||
FROM (SELECT store_code, platform_order_no, MIN(order_time) AS order_time, SUM(goods_amt) AS order_amt, MAX(consignee_add) AS order_addr
|
||||
FROM custom_online_sale_order_local
|
||||
GROUP BY store_code, platform_order_no
|
||||
) t1 LEFT JOIN (
|
||||
-- EC算运费
|
||||
SELECT store_code, platform_order_no, SUM(order_freight_amt_t) AS order_freight_amt
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
system_order_no,
|
||||
platform_order_no,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE source_system IN ('EC_HIS_NEW', 'EC_HIS2') AND order_freight_amt <> 0
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
) GROUP BY store_code, platform_order_no
|
||||
) t2 ON t1.store_code = t2.store_code AND t1.platform_order_no = t2.platform_order_no
|
||||
WHERE t1.order_time >= '2022-01-01' AND t1.order_time <= '2025-06-30' AND order_addr <> ''
|
||||
GROUP BY SUBSTR(t1.order_time, 1, 4), t1.order_addr
|
||||
ORDER BY SUBSTR(t1.order_time, 1, 4), (SUM(t1.order_amt) + SUM(t2.order_freight_amt)) DESC;
|
||||
|
||||
-- 省份+地址
|
||||
--SELECT COUNT() FROM custom_online_sale_order_local WHERE consignee_add = ''; -- 1869294
|
||||
--SELECT COUNT() FROM custom_online_sale_order_local WHERE province = ''; -- 1869251
|
||||
--SELECT COUNT() FROM custom_online_sale_order_local WHERE consignee_add = '' AND province = ''; -- 1869249
|
||||
--
|
||||
--SELECT
|
||||
-- SUBSTR(t1.order_time, 1, 4) AS "年份",
|
||||
-- t1.order_addr AS "收货地址",
|
||||
-- SUM(t1.order_amt) + SUM(t2.order_freight_amt) AS "销售金额(元)(包含运费)",
|
||||
-- SUM(t2.order_freight_amt) AS "运费金额(元)",
|
||||
-- COUNT(t1.platform_order_no) AS "订单数量"
|
||||
--FROM (SELECT store_code, platform_order_no, MIN(order_time) AS order_time, SUM(goods_amt) AS order_amt, MAX(CONCAT(province, consignee_add)) AS order_addr
|
||||
-- FROM custom_online_sale_order_local
|
||||
-- GROUP BY store_code, platform_order_no
|
||||
--) t1 LEFT JOIN (
|
||||
-- -- EC算运费
|
||||
-- SELECT store_code, platform_order_no, SUM(order_freight_amt_t) AS order_freight_amt
|
||||
-- FROM (SELECT
|
||||
-- store_code,
|
||||
-- system_order_no,
|
||||
-- platform_order_no,
|
||||
-- MAX(order_freight_amt) AS order_freight_amt_t
|
||||
-- FROM custom_online_sale_order_local
|
||||
-- WHERE source_system IN ('EC_HIS_NEW', 'EC_HIS2') AND order_freight_amt <> 0
|
||||
-- GROUP BY store_code, system_order_no, platform_order_no
|
||||
-- ) GROUP BY store_code, platform_order_no
|
||||
--) t2 ON t1.store_code = t2.store_code AND t1.platform_order_no = t2.platform_order_no
|
||||
--WHERE t1.order_time >= '2022-01-01' AND t1.order_time <= '2025-06-30' AND order_addr <> ''
|
||||
--GROUP BY SUBSTR(t1.order_time, 1, 4), t1.order_addr
|
||||
--ORDER BY SUBSTR(t1.order_time, 1, 4), (SUM(t1.order_amt) + SUM(t2.order_freight_amt)) DESC;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 3.3线上每年各天和各小时订单数量和销售金额
|
||||
-- order_time没有时分秒的数量 78954 SBZE3的部分单子 计算各小时的需要去除
|
||||
SELECT * FROM custom_online_sale_order_local WHERE LENGTH(order_time) <= 10;
|
||||
-- 账单order_time没有时分秒的数量 7364085
|
||||
SELECT COUNT() FROM custom_online_sale_bill_local WHERE LENGTH(order_time) <= 10;
|
||||
-- 账单的不能算订单数量
|
||||
SELECT
|
||||
SUBSTR(t1.order_time, 1, 4) AS "年份",
|
||||
SUBSTR(t1.order_time, 6, 5) AS "日期",
|
||||
SUM(t1.order_amt) + SUM(t2.order_freight_amt) AS "销售金额(元)(包含运费)",
|
||||
SUM(t2.order_freight_amt) AS "运费金额(元)",
|
||||
COUNT(t1.platform_order_no) AS "订单数量"
|
||||
FROM (SELECT store_code, platform_order_no, MIN(order_time) AS order_time, SUM(goods_amt) AS order_amt
|
||||
FROM custom_online_sale_order_local
|
||||
GROUP BY store_code, platform_order_no
|
||||
) t1 LEFT JOIN (
|
||||
-- EC算运费
|
||||
SELECT store_code, platform_order_no, SUM(order_freight_amt_t) AS order_freight_amt
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
system_order_no,
|
||||
platform_order_no,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE source_system IN ('EC_HIS_NEW', 'EC_HIS2') AND order_freight_amt <> 0
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
) GROUP BY store_code, platform_order_no
|
||||
) t2 ON t1.store_code = t2.store_code AND t1.platform_order_no = t2.platform_order_no
|
||||
WHERE t1.order_time >= '2022-01-01' AND t1.order_time <= '2025-06-30'
|
||||
GROUP BY SUBSTR(t1.order_time, 1, 4), SUBSTR(t1.order_time, 6, 5)
|
||||
ORDER BY SUBSTR(t1.order_time, 1, 4), (SUM(t1.order_amt) + SUM(t2.order_freight_amt)) DESC;
|
||||
|
||||
-- 账单店铺金额
|
||||
SELECT
|
||||
SUBSTR(order_time, 1, 4) AS "年份",
|
||||
SUBSTR(order_time, 6, 5) AS "日期",
|
||||
SUM(goods_amt) AS "销售金额(元)"
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt >= 0
|
||||
GROUP BY SUBSTR(order_time, 1, 4), SUBSTR(order_time, 6, 5)
|
||||
ORDER BY SUBSTR(order_time, 1, 4), SUM(goods_amt) DESC;
|
||||
|
||||
|
||||
-- 按照小时算 ----------
|
||||
SELECT
|
||||
SUBSTR(t1.order_time_t, 1, 4) AS "年份",
|
||||
t1.time_area AS "时间区间",
|
||||
SUM(t1.order_amt) + SUM(t2.order_freight_amt) AS "销售金额(元)(包含运费)",
|
||||
SUM(t2.order_freight_amt) AS "运费金额(元)",
|
||||
COUNT(t1.platform_order_no) AS "订单数量"
|
||||
FROM (SELECT store_code, platform_order_no, MIN(order_time) AS order_time_t, SUM(goods_amt) AS order_amt,
|
||||
CASE WHEN LENGTH(MIN(order_time)) > 10 THEN
|
||||
CASE
|
||||
WHEN toInt32(SUBSTR(MIN(order_time), 12, 2)) = 0 THEN '0-1点'
|
||||
WHEN toInt32(SUBSTR(MIN(order_time), 12, 2)) = 1 THEN '1-2点'
|
||||
WHEN toInt32(SUBSTR(MIN(order_time), 12, 2)) = 2 THEN '2-3点'
|
||||
WHEN toInt32(SUBSTR(MIN(order_time), 12, 2)) = 3 THEN '3-4点'
|
||||
WHEN toInt32(SUBSTR(MIN(order_time), 12, 2)) = 4 THEN '4-5点'
|
||||
WHEN toInt32(SUBSTR(MIN(order_time), 12, 2)) = 5 THEN '5-6点'
|
||||
WHEN toInt32(SUBSTR(MIN(order_time), 12, 2)) = 6 THEN '6-7点'
|
||||
WHEN toInt32(SUBSTR(MIN(order_time), 12, 2)) = 7 THEN '7-8点'
|
||||
WHEN toInt32(SUBSTR(MIN(order_time), 12, 2)) = 8 THEN '8-9点'
|
||||
WHEN toInt32(SUBSTR(MIN(order_time), 12, 2)) = 9 THEN '9-10点'
|
||||
WHEN toInt32(SUBSTR(MIN(order_time), 12, 2)) = 10 THEN '10-11点'
|
||||
WHEN toInt32(SUBSTR(MIN(order_time), 12, 2)) = 11 THEN '11-12点'
|
||||
WHEN toInt32(SUBSTR(MIN(order_time), 12, 2)) = 12 THEN '12-13点'
|
||||
WHEN toInt32(SUBSTR(MIN(order_time), 12, 2)) = 13 THEN '13-14点'
|
||||
WHEN toInt32(SUBSTR(MIN(order_time), 12, 2)) = 14 THEN '14-15点'
|
||||
WHEN toInt32(SUBSTR(MIN(order_time), 12, 2)) = 15 THEN '15-16点'
|
||||
WHEN toInt32(SUBSTR(MIN(order_time), 12, 2)) = 16 THEN '16-17点'
|
||||
WHEN toInt32(SUBSTR(MIN(order_time), 12, 2)) = 17 THEN '17-18点'
|
||||
WHEN toInt32(SUBSTR(MIN(order_time), 12, 2)) = 18 THEN '18-19点'
|
||||
WHEN toInt32(SUBSTR(MIN(order_time), 12, 2)) = 19 THEN '19-20点'
|
||||
WHEN toInt32(SUBSTR(MIN(order_time), 12, 2)) = 20 THEN '20-21点'
|
||||
WHEN toInt32(SUBSTR(MIN(order_time), 12, 2)) = 21 THEN '21-22点'
|
||||
WHEN toInt32(SUBSTR(MIN(order_time), 12, 2)) = 22 THEN '22-23点'
|
||||
WHEN toInt32(SUBSTR(MIN(order_time), 12, 2)) = 23 THEN '23-24点'
|
||||
END
|
||||
ELSE '其他' END AS time_area
|
||||
FROM custom_online_sale_order_local
|
||||
GROUP BY store_code, platform_order_no
|
||||
) t1 LEFT JOIN (
|
||||
-- EC算运费
|
||||
SELECT store_code, platform_order_no, SUM(order_freight_amt_t) AS order_freight_amt
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
system_order_no,
|
||||
platform_order_no,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE source_system IN ('EC_HIS_NEW', 'EC_HIS2') AND order_freight_amt <> 0
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
) GROUP BY store_code, platform_order_no
|
||||
) t2 ON t1.store_code = t2.store_code AND t1.platform_order_no = t2.platform_order_no
|
||||
WHERE t1.order_time_t >= '2022-01-01' AND t1.order_time_t <= '2025-06-30' AND time_area <> '其他'
|
||||
GROUP BY SUBSTR(t1.order_time_t, 1, 4), t1.time_area
|
||||
ORDER BY SUBSTR(t1.order_time_t, 1, 4), (SUM(t1.order_amt) + SUM(t2.order_freight_amt)) DESC;
|
||||
|
||||
-- 账单店铺金额
|
||||
-- 22 23年没有带时间的
|
||||
SELECT
|
||||
SUBSTR(order_time, 1, 4) AS "年份",
|
||||
time_area AS "时间区间",
|
||||
SUM(goods_amt) AS "销售金额(元)"
|
||||
FROM (SELECT
|
||||
order_time,
|
||||
CASE
|
||||
WHEN toInt32(SUBSTR(order_time, 12, 2)) = 0 THEN '0-1点'
|
||||
WHEN toInt32(SUBSTR(order_time, 12, 2)) = 1 THEN '1-2点'
|
||||
WHEN toInt32(SUBSTR(order_time, 12, 2)) = 2 THEN '2-3点'
|
||||
WHEN toInt32(SUBSTR(order_time, 12, 2)) = 3 THEN '3-4点'
|
||||
WHEN toInt32(SUBSTR(order_time, 12, 2)) = 4 THEN '4-5点'
|
||||
WHEN toInt32(SUBSTR(order_time, 12, 2)) = 5 THEN '5-6点'
|
||||
WHEN toInt32(SUBSTR(order_time, 12, 2)) = 6 THEN '6-7点'
|
||||
WHEN toInt32(SUBSTR(order_time, 12, 2)) = 7 THEN '7-8点'
|
||||
WHEN toInt32(SUBSTR(order_time, 12, 2)) = 8 THEN '8-9点'
|
||||
WHEN toInt32(SUBSTR(order_time, 12, 2)) = 9 THEN '9-10点'
|
||||
WHEN toInt32(SUBSTR(order_time, 12, 2)) = 10 THEN '10-11点'
|
||||
WHEN toInt32(SUBSTR(order_time, 12, 2)) = 11 THEN '11-12点'
|
||||
WHEN toInt32(SUBSTR(order_time, 12, 2)) = 12 THEN '12-13点'
|
||||
WHEN toInt32(SUBSTR(order_time, 12, 2)) = 13 THEN '13-14点'
|
||||
WHEN toInt32(SUBSTR(order_time, 12, 2)) = 14 THEN '14-15点'
|
||||
WHEN toInt32(SUBSTR(order_time, 12, 2)) = 15 THEN '15-16点'
|
||||
WHEN toInt32(SUBSTR(order_time, 12, 2)) = 16 THEN '16-17点'
|
||||
WHEN toInt32(SUBSTR(order_time, 12, 2)) = 17 THEN '17-18点'
|
||||
WHEN toInt32(SUBSTR(order_time, 12, 2)) = 18 THEN '18-19点'
|
||||
WHEN toInt32(SUBSTR(order_time, 12, 2)) = 19 THEN '19-20点'
|
||||
WHEN toInt32(SUBSTR(order_time, 12, 2)) = 20 THEN '20-21点'
|
||||
WHEN toInt32(SUBSTR(order_time, 12, 2)) = 21 THEN '21-22点'
|
||||
WHEN toInt32(SUBSTR(order_time, 12, 2)) = 22 THEN '22-23点'
|
||||
WHEN toInt32(SUBSTR(order_time, 12, 2)) = 23 THEN '23-24点'
|
||||
END AS time_area,
|
||||
goods_amt
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt >= 0 AND LENGTH(order_time) > 10
|
||||
) GROUP BY SUBSTR(order_time, 1, 4), time_area
|
||||
ORDER BY SUBSTR(order_time, 1, 4), SUM(goods_amt) DESC;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 3.4线上每年大促期间店铺销售金额、订单数量和占比
|
||||
SELECT
|
||||
t1.store_code AS "店铺编码",
|
||||
MAX(t1.store_name) AS "店铺名称",
|
||||
SUM(t1.order_amt) + SUM(t2.order_freight_amt) AS "销售金额(元)(包含运费)",
|
||||
SUM(t2.order_freight_amt) AS "运费金额(元)",
|
||||
COUNT(t1.platform_order_no) AS "订单数量"
|
||||
FROM (SELECT store_code, platform_order_no, MAX(store_name) AS store_name, MIN(order_time) AS order_time, SUM(goods_amt) AS order_amt
|
||||
FROM custom_online_sale_order_local
|
||||
GROUP BY store_code, platform_order_no
|
||||
) t1 LEFT JOIN (
|
||||
-- EC算运费
|
||||
SELECT store_code, platform_order_no, SUM(order_freight_amt_t) AS order_freight_amt
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
system_order_no,
|
||||
platform_order_no,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE source_system IN ('EC_HIS_NEW', 'EC_HIS2') AND order_freight_amt <> 0
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
) GROUP BY store_code, platform_order_no
|
||||
) t2 ON t1.store_code = t2.store_code AND t1.platform_order_no = t2.platform_order_no
|
||||
WHERE t1.order_time >= '2022-06-01' AND t1.order_time <= '2022-06-30'
|
||||
GROUP BY t1.store_code
|
||||
ORDER BY (SUM(t1.order_amt) + SUM(t2.order_freight_amt)) DESC;
|
||||
|
||||
-- 账单店铺金额
|
||||
SELECT
|
||||
store_code AS "店铺编码",
|
||||
MAX(store_name) AS "店铺名称",
|
||||
SUM(goods_amt) AS "销售金额(元)"
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt >= 0 AND order_time >= '2022-06-01' AND order_time <= '2022-06-30'
|
||||
GROUP BY store_code
|
||||
ORDER BY SUM(goods_amt) DESC;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 4.1线上每年订单下单和发货间隔的销售金额、订单数量分布
|
||||
-- 1586424条平台订单物流单号为空
|
||||
SELECT source_system, COUNT() FROM custom_online_sale_order_local WHERE main_logistic_bill = '' GROUP BY source_system;
|
||||
-- 1,780,404 条平台订单发货时间为空
|
||||
SELECT source_system, COUNT() FROM custom_online_sale_order_local WHERE deliver_time = '' GROUP BY source_system;
|
||||
-- SBZ XSDD的40条财务手工的单子发货时间不为空,其他都为空 账单的做不了
|
||||
SELECT * FROM custom_online_sale_bill_local WHERE deliver_time <> '';
|
||||
|
||||
SELECT
|
||||
SUBSTR(t1.order_time_t, 1, 4) AS "年份",
|
||||
t1.time_diff AS "发货间隔",
|
||||
SUM(t1.order_amt) + SUM(t2.order_freight_amt) AS "销售金额(元)(包含运费)",
|
||||
SUM(t2.order_freight_amt) AS "运费金额(元)",
|
||||
COUNT(t1.platform_order_no) AS "订单数量"
|
||||
FROM (SELECT store_code, platform_order_no, MIN(order_time) AS order_time_t, MIN(deliver_time) AS deliver_time_t, SUM(goods_amt) AS order_amt,
|
||||
CASE WHEN MIN(deliver_time) <> '' AND MIN(order_time) <> '' THEN
|
||||
CASE
|
||||
WHEN dateDiff('minute', toDateTime(MIN(deliver_time)), toDateTime(MIN(order_time))) <= 240 THEN '0-4小时'
|
||||
WHEN dateDiff('minute', toDateTime(MIN(deliver_time)), toDateTime(MIN(order_time))) > 240
|
||||
AND dateDiff('minute', toDateTime(MIN(deliver_time)), toDateTime(MIN(order_time))) <= 1440 THEN '4-24小时'
|
||||
WHEN dateDiff('minute', toDateTime(MIN(deliver_time)), toDateTime(MIN(order_time))) > 1440
|
||||
AND dateDiff('minute', toDateTime(MIN(deliver_time)), toDateTime(MIN(order_time))) <= 2880 THEN '24-48小时'
|
||||
WHEN dateDiff('minute', toDateTime(MIN(deliver_time)), toDateTime(MIN(order_time))) > 2880 THEN '大于48小时'
|
||||
END
|
||||
ELSE '其他'
|
||||
END AS time_diff
|
||||
FROM custom_online_sale_order_local
|
||||
GROUP BY store_code, platform_order_no
|
||||
) t1 LEFT JOIN (
|
||||
-- EC算运费
|
||||
SELECT store_code, platform_order_no, SUM(order_freight_amt_t) AS order_freight_amt
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
system_order_no,
|
||||
platform_order_no,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE source_system IN ('EC_HIS_NEW', 'EC_HIS2') AND order_freight_amt <> 0
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
) GROUP BY store_code, platform_order_no
|
||||
) t2 ON t1.store_code = t2.store_code AND t1.platform_order_no = t2.platform_order_no
|
||||
WHERE t1.order_time_t >= '2022-01-01' AND t1.order_time_t <= '2025-06-30' AND time_diff <> '其他'
|
||||
GROUP BY SUBSTR(t1.order_time_t, 1, 4), t1.time_diff
|
||||
ORDER BY SUBSTR(t1.order_time_t, 1, 4), (SUM(t1.order_amt) + SUM(t2.order_freight_amt)) DESC;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 4.2线上每年各物流承运商销售金额、订单数量
|
||||
-- 932303条平台订单物流承运商为空 账单的为SBZ 40条财务手工单,无平台订单号不考虑
|
||||
SELECT COUNT(DISTINCT platform_order_no) FROM custom_online_sale_order_local WHERE carrier = '';
|
||||
|
||||
SELECT carrier, COUNT(DISTINCT platform_order_no) FROM custom_online_sale_order_local GROUP BY carrier;
|
||||
|
||||
SELECT
|
||||
SUBSTR(t1.order_time, 1, 4) AS "年份",
|
||||
t1.carrierName AS "承运商",
|
||||
SUM(t1.order_amt) + SUM(t2.order_freight_amt) AS "销售金额(元)(包含运费)",
|
||||
SUM(t2.order_freight_amt) AS "运费金额(元)",
|
||||
COUNT(t1.platform_order_no) AS "订单数量"
|
||||
FROM (SELECT store_code, platform_order_no, MIN(order_time) AS order_time, SUM(goods_amt) AS order_amt, MAX(carrier) AS carrier,
|
||||
CASE
|
||||
WHEN carrier IN ('shunfeng') OR carrier LIKE 'sf%' OR carrier LIKE 'SF%' OR carrier LIKE '顺丰%' THEN '顺丰'
|
||||
WHEN carrier IN ('postb', 'eyb') OR carrier LIKE 'ems%' OR carrier LIKE 'EMS%' THEN '邮政'
|
||||
WHEN carrier LIKE 'yunda%' OR carrier LIKE 'YUNDA%' THEN '韵达'
|
||||
WHEN carrier IN ('ZT') OR carrier LIKE 'zto%' OR carrier LIKE 'ZTO%' OR carrier LIKE '中通%' THEN '中通'
|
||||
WHEN carrier LIKE 'jd%' OR carrier LIKE 'JD%' OR carrier LIKE '京东%' THEN '京东'
|
||||
WHEN carrier IN ('ST#DW', 'ST') OR carrier LIKE 'sto%' OR carrier LIKE 'STO%' OR carrier LIKE '申通%' THEN '申通'
|
||||
WHEN carrier LIKE 'jt%' OR carrier LIKE 'JT%' THEN '极兔'
|
||||
WHEN carrier IN ('YT') OR carrier LIKE 'yto%' OR carrier LIKE 'YTO%' OR carrier LIKE '圆通%' THEN '圆通'
|
||||
WHEN carrier IN ('rider') THEN '骑士'
|
||||
WHEN carrier IN ('dbl') THEN '德邦'
|
||||
WHEN carrier IN ('htky') THEN '汇通'
|
||||
WHEN carrier IN ('QSKD') THEN '千顺'
|
||||
WHEN carrier IN ('fengwang') THEN '丰网'
|
||||
WHEN carrier IN ('best') THEN '百世'
|
||||
WHEN carrier IN ('ttkdex') THEN '天天'
|
||||
ELSE carrier
|
||||
END AS carrierName
|
||||
FROM custom_online_sale_order_local
|
||||
GROUP BY store_code, platform_order_no
|
||||
) t1 LEFT JOIN (
|
||||
-- EC算运费
|
||||
SELECT store_code, platform_order_no, SUM(order_freight_amt_t) AS order_freight_amt
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
system_order_no,
|
||||
platform_order_no,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE source_system IN ('EC_HIS_NEW', 'EC_HIS2') AND order_freight_amt <> 0
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
) GROUP BY store_code, platform_order_no
|
||||
) t2 ON t1.store_code = t2.store_code AND t1.platform_order_no = t2.platform_order_no
|
||||
WHERE t1.order_time >= '2022-01-01' AND t1.order_time <= '2025-06-30'
|
||||
GROUP BY SUBSTR(t1.order_time, 1, 4), t1.carrierName
|
||||
ORDER BY SUBSTR(t1.order_time, 1, 4), (SUM(t1.order_amt) + SUM(t2.order_freight_amt)) DESC;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 4.3线上每年各月物流单数量
|
||||
-- 按照最小下单时间,物流单往前归
|
||||
SELECT
|
||||
SUBSTR(t2.order_time_t, 1, 4) AS "年份",
|
||||
SUBSTR(t2.order_time_t, 6, 2) AS "月份",
|
||||
COUNT(DISTINCT t1.main_logistic_bill) AS "物流单数量"
|
||||
FROM (SELECT *
|
||||
FROM custom_online_sale_order_local
|
||||
) t1 LEFT JOIN (SELECT store_code, platform_order_no, MIN(order_time) AS order_time_t
|
||||
FROM custom_online_sale_order_local
|
||||
GROUP BY store_code, platform_order_no
|
||||
) t2 ON t1.store_code = t2.store_code AND t1.platform_order_no = t2.platform_order_no
|
||||
WHERE t2.order_time_t >= '2022-01-01' AND t2.order_time_t <= '2025-06-30' AND main_logistic_bill <> ''
|
||||
GROUP BY SUBSTR(t2.order_time_t, 1, 4), SUBSTR(t2.order_time_t, 6, 2)
|
||||
ORDER BY SUBSTR(t2.order_time_t, 1, 4), SUBSTR(t2.order_time_t, 6, 2);
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 5.1线上各店铺每年度退款金额
|
||||
-- 换货的退款怎么区分
|
||||
SELECT
|
||||
SUBSTR(t1.order_time, 1, 4) AS "年份",
|
||||
t1.store_code AS "店铺编码",
|
||||
MAX(t1.store_name) AS "店铺名称",
|
||||
SUM(t1.order_amt) + SUM(t2.order_freight_amt) AS "销售金额(元)(包含运费)",
|
||||
SUM(t2.order_freight_amt) AS "运费金额(元)",
|
||||
COUNT(t1.platform_order_no) AS "订单数量",
|
||||
ROUND((SUM(t1.order_amt) + SUM(t2.order_freight_amt)) / COUNT(t1.platform_order_no), 2) AS "订单均价(元)"
|
||||
FROM (SELECT store_code, platform_order_no, MAX(store_name) AS store_name, MIN(create_time) AS create_time, SUM(goods_amt) AS order_amt
|
||||
FROM custom_online_sale_return_local
|
||||
GROUP BY store_code, platform_order_no
|
||||
) t1 LEFT JOIN (
|
||||
-- EC算运费
|
||||
SELECT store_code, platform_order_no, SUM(order_freight_amt_t) AS order_freight_amt
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
system_order_no,
|
||||
platform_order_no,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE source_system IN ('EC_HIS_NEW', 'EC_HIS2') AND order_freight_amt <> 0
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
) GROUP BY store_code, platform_order_no
|
||||
) t2 ON t1.store_code = t2.store_code AND t1.platform_order_no = t2.platform_order_no
|
||||
WHERE t1.order_time >= '2022-01-01' AND t1.order_time <= '2025-06-30'
|
||||
GROUP BY SUBSTR(t1.order_time, 1, 4), t1.store_code
|
||||
ORDER BY SUBSTR(t1.order_time, 1, 4), (SUM(t1.order_amt) + SUM(t2.order_freight_amt)) DESC;
|
||||
|
||||
-- 账单店铺金额
|
||||
SELECT
|
||||
SUBSTR(order_time, 1, 4) AS "年份",
|
||||
store_code AS "店铺编码",
|
||||
MAX(store_name) AS "店铺名称",
|
||||
SUM(goods_amt) AS "退款金额(元)"
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt < 0
|
||||
GROUP BY SUBSTR(order_time, 1, 4), store_code
|
||||
ORDER BY SUBSTR(order_time, 1, 4), SUM(goods_amt) DESC;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 5.2线上各店铺每年退款订单数量
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 5.3线上每年退款大于原销售的差异金额、订单数量
|
||||
|
||||
-- xxxxxxxxxxxxxxxxx
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 5.4线上每年各月退款金额
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 5.5线上每年各月退款订单数量
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 5.6线上每年订单退款金额分布
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 6.1线上每年净销售金额前100订单净销售金额
|
||||
|
||||
-- xxxxxxxxxxxxxxxxx
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 6.2线上每年净销售金额前100订单各省份净销售金额
|
||||
|
||||
-- xxxxxxxxxxxxxxxxx
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 6.3线上每年净销售金额前100订单各商品净销售金额
|
||||
|
||||
-- xxxxxxxxxxxxxxxxx
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 7.1线上每年会员数量
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 7.2线上每年活跃会员数量及其占比
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 7.3线上每年会员新增、注销数量
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 7.4线上每年会员积分新增、消耗、清零数量
|
||||
|
||||
------------------------------------------------------------------
|
985
数据分析/v3/正式-查询-钱货两清时间.sql
Normal file
985
数据分析/v3/正式-查询-钱货两清时间.sql
Normal file
@@ -0,0 +1,985 @@
|
||||
-- 1.1线上各店铺每年度销售金额、订单数量、订单均价
|
||||
-- 数量和单价只能计算有订单的,账单的不能算
|
||||
SELECT
|
||||
SUBSTR(mgclear_time_t, 1, 4) AS "年份",
|
||||
store_code AS "店铺编码",
|
||||
MAX(store_name_t) AS "店铺名称",
|
||||
SUM(goods_amt_t) AS "销售金额(元)",
|
||||
SUM(order_freight_amt_t) AS "运费金额(元)",
|
||||
SUM(goods_amt_t) + SUM(order_freight_amt_t) AS "销售金额(元)(包含运费)",
|
||||
COUNT(DISTINCT platform_order_no) AS "订单数量",
|
||||
ROUND((SUM(goods_amt_t) + SUM(order_freight_amt_t)) / COUNT(DISTINCT platform_order_no), 2) AS "订单均价(元)"
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
MAX(store_name) AS store_name_t,
|
||||
system_order_no,
|
||||
platform_order_no,
|
||||
MIN(mgclear_time) AS mgclear_time_t,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t,
|
||||
SUM(goods_qty) AS goods_qty_t,
|
||||
SUM(goods_amt) AS goods_amt_t
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30'
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
)
|
||||
GROUP BY SUBSTR(mgclear_time_t, 1, 4), store_code
|
||||
ORDER BY SUBSTR(mgclear_time_t, 1, 4), SUM(goods_amt_t) + SUM(order_freight_amt_t) DESC;
|
||||
|
||||
-- 账单店铺金额
|
||||
SELECT
|
||||
SUBSTR(mgclear_time, 1, 4) AS "年份",
|
||||
store_code AS "店铺编码",
|
||||
MAX(store_name) AS "店铺名称",
|
||||
SUM(goods_amt) AS "销售金额(元)"
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt >= 0 AND mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30'
|
||||
GROUP BY SUBSTR(mgclear_time, 1, 4), store_code
|
||||
ORDER BY SUBSTR(mgclear_time, 1, 4), SUM(goods_amt) DESC;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 1.2线上各店铺每年度净销售金额
|
||||
SELECT
|
||||
t1.perYear AS "年份",
|
||||
t1.store_code AS "店铺编码",
|
||||
t1.storeName AS "店铺名称",
|
||||
t1.goodsAmt AS "销售金额(元)",
|
||||
t1.orderFreightAmt AS "运费金额(元)",
|
||||
t2.returnGoodsAmt AS "退货金额(元)",
|
||||
t2.returnFreightAmt AS "退货运费金额(元)",
|
||||
t3.orderChangeAmt AS "发货调整金额(元)",
|
||||
t1.goodsAmt + t1.orderFreightAmt + t2.returnGoodsAmt
|
||||
+ t2.returnFreightAmt + t3.orderChangeAmt AS "净销售金额(元)"
|
||||
FROM (
|
||||
SELECT
|
||||
SUBSTR(mgclear_time_t, 1, 4) AS perYear,
|
||||
store_code,
|
||||
MAX(store_name_t) AS storeName,
|
||||
SUM(goods_amt_t) AS goodsAmt,
|
||||
SUM(order_freight_amt_t) AS orderFreightAmt
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
MAX(store_name) AS store_name_t,
|
||||
system_order_no,
|
||||
platform_order_no,
|
||||
MIN(mgclear_time) AS mgclear_time_t,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t,
|
||||
SUM(goods_qty) AS goods_qty_t,
|
||||
SUM(goods_amt) AS goods_amt_t
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30'
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
) GROUP BY SUBSTR(mgclear_time_t, 1, 4), store_code
|
||||
) t1 LEFT JOIN (
|
||||
SELECT
|
||||
SUBSTR(mgclear_time_t, 1, 4) AS perYear,
|
||||
store_code,
|
||||
SUM(return_freight_amt_t) AS returnFreightAmt,
|
||||
SUM(return_goods_amt_t) AS returnGoodsAmt
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
system_order_no,
|
||||
platform_order_no,
|
||||
MIN(mgclear_time) AS mgclear_time_t,
|
||||
MAX(return_freight_amt) AS return_freight_amt_t,
|
||||
SUM(return_goods_qty) AS return_goods_qty_t,
|
||||
SUM(return_goods_amt) AS return_goods_amt_t
|
||||
FROM custom_online_sale_return_local
|
||||
WHERE mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30'
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
) GROUP BY SUBSTR(mgclear_time_t, 1, 4), store_code
|
||||
) t2 ON t1.perYear = t2.perYear AND t1.store_code = t2.store_code
|
||||
LEFT JOIN (
|
||||
SELECT SUBSTR(mgclear_time, 1, 4) AS perYear, store_code, SUM(special_barcode_amt) AS orderChangeAmt
|
||||
FROM custom_online_sale_change_local
|
||||
WHERE mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30'
|
||||
GROUP BY SUBSTR(mgclear_time, 1, 4), store_code
|
||||
) t3 ON t1.perYear = t3.perYear AND t1.store_code = t3.store_code
|
||||
ORDER BY t1.perYear, t1.goodsAmt + t1.orderFreightAmt + t2.returnGoodsAmt
|
||||
+ t2.returnFreightAmt + t3.orderChangeAmt DESC;
|
||||
|
||||
-- 账单店铺金额
|
||||
SELECT
|
||||
t1.perYear AS "年份",
|
||||
t1.store_code AS "店铺编码",
|
||||
t1.store_name AS "店铺名称",
|
||||
t1.sale_amount AS "销售金额(元)",
|
||||
t2.return_amount AS "退货金额(元)",
|
||||
t1.sale_amount + t2.return_amount AS "净销售金额(元)"
|
||||
FROM (SELECT
|
||||
SUBSTR(mgclear_time, 1, 4) AS perYear,
|
||||
store_code,
|
||||
MAX(store_name) AS store_name,
|
||||
SUM(goods_amt) AS sale_amount
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt >= 0 AND mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30'
|
||||
GROUP BY SUBSTR(mgclear_time, 1, 4), store_code
|
||||
) t1 LEFT JOIN (
|
||||
SELECT
|
||||
SUBSTR(mgclear_time, 1, 4) AS perYear,
|
||||
store_code,
|
||||
SUM(goods_amt) AS return_amount
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt < 0 AND mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30'
|
||||
GROUP BY SUBSTR(mgclear_time, 1, 4), store_code
|
||||
) t2 ON t1.perYear = t2.perYear AND t1.store_code = t2.store_code
|
||||
ORDER BY t1.perYear, (t1.sale_amount + t2.return_amount) DESC;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 1.3线上各店铺每年月度销售金额
|
||||
SELECT
|
||||
SUBSTR(mgclear_time_t, 1, 4) AS "年份",
|
||||
SUBSTR(mgclear_time_t, 6, 2) AS "月份",
|
||||
store_code AS "店铺编码",
|
||||
MAX(store_name_t) AS "店铺名称",
|
||||
SUM(goods_amt_t) AS "销售金额(元)",
|
||||
SUM(order_freight_amt_t) AS "运费金额(元)",
|
||||
SUM(goods_amt_t) + SUM(order_freight_amt_t) AS "销售金额(元)(包含运费)",
|
||||
COUNT(DISTINCT platform_order_no) AS "订单数量",
|
||||
ROUND((SUM(goods_amt_t) + SUM(order_freight_amt_t)) / COUNT(DISTINCT platform_order_no), 2) AS "订单均价(元)"
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
MAX(store_name) AS store_name_t,
|
||||
system_order_no,
|
||||
platform_order_no,
|
||||
MIN(mgclear_time) AS mgclear_time_t,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t,
|
||||
SUM(goods_qty) AS goods_qty_t,
|
||||
SUM(goods_amt) AS goods_amt_t
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30'
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
)
|
||||
GROUP BY SUBSTR(mgclear_time_t, 1, 4), SUBSTR(mgclear_time_t, 6, 2), store_code
|
||||
ORDER BY SUBSTR(mgclear_time_t, 1, 4), store_code, SUBSTR(mgclear_time_t, 6, 2);
|
||||
|
||||
-- 账单店铺金额
|
||||
SELECT
|
||||
SUBSTR(mgclear_time, 1, 4) AS "年份",
|
||||
SUBSTR(mgclear_time, 6, 2) AS "月份",
|
||||
store_code AS "店铺编码",
|
||||
MAX(store_name) AS "店铺名称",
|
||||
SUM(goods_amt) AS "销售金额(元)"
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt >= 0 AND mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30'
|
||||
GROUP BY SUBSTR(mgclear_time, 1, 4), SUBSTR(mgclear_time, 6, 2), store_code
|
||||
ORDER BY SUBSTR(mgclear_time, 1, 4), store_code, SUBSTR(mgclear_time, 6, 2);
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 1.4线上每年前五店铺金额分布
|
||||
|
||||
-- xxxxxxxxxxxxxxxxx
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 1.5线上每年各产品数量、产品销售金额
|
||||
-- 订单中6条商品为空的, 忽略
|
||||
SELECT COUNT() FROM custom_online_sale_order_local WHERE goods_barcode ='';
|
||||
|
||||
SELECT * FROM custom_online_sale_order_local;
|
||||
|
||||
SELECT * FROM dim_hkaudit_goods_mt WHERE barcode IN (
|
||||
SELECT barcode
|
||||
FROM dim_hkaudit_goods_mt GROUP BY barcode HAVING COUNT(DISTINCT goods_code) > 1)
|
||||
ORDER By barcode ;
|
||||
|
||||
SELECT * FROM dim_hkaudit_goods_mt dhgm WHERE barcode = 'VRDBJ41159A01001A11';
|
||||
SELECT * FROM dim_hkaudit_goods_mt WHERE goods_code IN (SELECT goods_barcode FROM audit_bi_pro.custom_online_sale_order_local);
|
||||
|
||||
|
||||
SELECT * FROM dim_hkaudit_goods_mt a left join custom_online_sale_order_local b on a.barcode = b.goods_barcode ;
|
||||
|
||||
SELECT COUNT() FROM dim_hkaudit_goods_mt;
|
||||
SELECT COUNT() FROM dim_hkaudit_goods_mt_local;
|
||||
|
||||
-- 不关联商品名称(每个表单独算)
|
||||
--SELECT
|
||||
-- SUBSTR(mgclear_time, 1, 4) AS "年份",
|
||||
-- goods_barcode AS "商品条码",
|
||||
-- SUM(goods_qty) AS "商品数量",
|
||||
-- SUM(goods_amt) AS "商品销售金额(元)"
|
||||
--FROM custom_online_sale_order_local
|
||||
--WHERE mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30'
|
||||
--GROUP BY SUBSTR(mgclear_time, 1, 4), goods_barcode
|
||||
--ORDER BY SUBSTR(mgclear_time, 1, 4), SUM(goods_amt) DESC;
|
||||
|
||||
-- 账单店铺金额
|
||||
--SELECT
|
||||
-- SUBSTR(mgclear_time, 1, 4) AS "年份",
|
||||
-- goods_barcode AS "商品条码",
|
||||
-- SUM(goods_qty) AS "商品数量",
|
||||
-- SUM(goods_amt) AS "商品销售金额(元)"
|
||||
--FROM custom_online_sale_bill_local
|
||||
--WHERE goods_amt >= 0 mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30'
|
||||
--GROUP BY SUBSTR(mgclear_time, 1, 4), goods_barcode
|
||||
--ORDER BY SUBSTR(mgclear_time, 1, 4), SUM(goods_amt) DESC;
|
||||
|
||||
-- 关联名称
|
||||
--SELECT
|
||||
-- SUBSTR(t1.mgclear_time, 1, 4) AS "年份",
|
||||
-- t1.goods_barcode AS "商品条码",
|
||||
-- MAX(t2.goods_names) AS "商品名称(多个合并)",
|
||||
-- SUM(t1.goods_qty) AS "商品数量",
|
||||
-- SUM(t1.goods_amt) AS "商品销售金额(元)"
|
||||
--FROM custom_online_sale_order_local t1
|
||||
--LEFT JOIN (SELECT barcode, arrayStringConcat(groupArray(goods_desc), ',') AS goods_names FROM dim_hkaudit_goods_mt GROUP BY barcode
|
||||
--) t2 ON t1.goods_barcode = t2.barcode
|
||||
--WHERE t1.mgclear_time <> '' AND SUBSTR(t1.mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(t1.mgclear_time, 1, 10) <= '2025-06-30'
|
||||
--GROUP BY SUBSTR(t1.mgclear_time, 1, 4), t1.goods_barcode
|
||||
--ORDER BY SUBSTR(t1.mgclear_time, 1, 4), SUM(t1.goods_amt) DESC;
|
||||
|
||||
----------------------
|
||||
-- 不关联商品名称(两表合并算)
|
||||
--SELECT
|
||||
-- perYear AS "年份",
|
||||
-- goods_barcode AS "商品条码",
|
||||
-- SUM(goods_qty) AS "商品数量",
|
||||
-- SUM(goods_amt) AS "商品销售金额(元)"
|
||||
--FROM (SELECT
|
||||
-- SUBSTR(mgclear_time, 1, 4) AS perYear,
|
||||
-- goods_barcode,
|
||||
-- goods_qty,
|
||||
-- goods_amt
|
||||
-- FROM custom_online_sale_order_local
|
||||
-- WHERE mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30'
|
||||
-- UNION ALL
|
||||
-- SELECT
|
||||
-- SUBSTR(mgclear_time, 1, 4) AS perYear,
|
||||
-- goods_barcode,
|
||||
-- goods_qty,
|
||||
-- goods_amt
|
||||
-- FROM custom_online_sale_bill_local
|
||||
-- WHERE goods_amt >= 0 AND mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30'
|
||||
--)
|
||||
--GROUP BY perYear, goods_barcode
|
||||
--ORDER BY perYear, SUM(goods_amt) DESC;
|
||||
|
||||
-- 关联商品名称
|
||||
SELECT
|
||||
t1.perYear AS "年份",
|
||||
t1.goods_barcode AS "商品条码",
|
||||
MAX(t2.goods_names) AS "商品名称(多个合并)",
|
||||
SUM(t1.goods_qty) AS "商品数量",
|
||||
SUM(t1.goods_amt) AS "商品销售金额(元)"
|
||||
FROM (SELECT
|
||||
SUBSTR(mgclear_time, 1, 4) AS perYear,
|
||||
goods_barcode,
|
||||
goods_qty,
|
||||
goods_amt
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30'
|
||||
UNION ALL
|
||||
SELECT
|
||||
SUBSTR(mgclear_time, 1, 4) AS perYear,
|
||||
goods_barcode,
|
||||
goods_qty,
|
||||
goods_amt
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt >= 0 AND mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30'
|
||||
) t1 LEFT JOIN (
|
||||
SELECT barcode, arrayStringConcat(groupArray(goods_desc), ',') AS goods_names FROM dim_hkaudit_goods_mt GROUP BY barcode
|
||||
) t2 ON t1.goods_barcode = t2.barcode
|
||||
GROUP BY t1.perYear, t1.goods_barcode
|
||||
ORDER BY t1.perYear, SUM(t1.goods_amt) DESC;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 2.1线上每年各省份销售金额、订单数量及其占比
|
||||
-- 1234791条平台订单没有省份
|
||||
SELECT COUNT(DISTINCT platform_order_no) FROM custom_online_sale_order_local WHERE province = '';
|
||||
SELECT source_system, COUNT(DISTINCT platform_order_no) FROM custom_online_sale_order_local WHERE province = '' GROUP BY source_system;
|
||||
-- 只能计算有订单的,账单的不能算(没有省份)
|
||||
-- 考虑店铺单号重复问题 非换货单有946单重复,加上换货单有1229条重复
|
||||
-- 忽略省份为空的平台订单
|
||||
-- 同一平台订单号在多个店铺存在的有1230单 暂时不考虑这种情况
|
||||
SELECT COUNT() FROM (
|
||||
SELECT platform_order_no FROM custom_online_sale_order_local GROUP BY platform_order_no HAVING COUNT(DISTINCT store_code) > 1);
|
||||
|
||||
SELECT
|
||||
a.perYear AS "年份",
|
||||
a.province_t AS "省份",
|
||||
a.goodsAmt AS "销售金额(元)",
|
||||
a.orderFreightAmt AS "运费金额(元)",
|
||||
a.goodsAmt + a.orderFreightAmt AS "销售金额(元)(包含运费)",
|
||||
a.order_amt AS "订单数量",
|
||||
b.all_order_count AS "订单总数量",
|
||||
ROUND((a.goodsAmt + a.orderFreightAmt) / b.all_order_count, 2) AS "订单占比"
|
||||
FROM (SELECT
|
||||
SUBSTR(mgclear_time_t, 1, 4) AS perYear,
|
||||
province_t,
|
||||
SUM(goods_amt_t) AS goodsAmt,
|
||||
SUM(order_freight_amt_t) AS orderFreightAmt,
|
||||
COUNT(DISTINCT platform_order_no) AS order_amt
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
MAX(store_name) AS store_name_t,
|
||||
system_order_no,
|
||||
platform_order_no,
|
||||
MIN(mgclear_time) AS mgclear_time_t,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t,
|
||||
SUM(goods_qty) AS goods_qty_t,
|
||||
SUM(goods_amt) AS goods_amt_t,
|
||||
MAX(province) AS province_t
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30' AND province <> ''
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
)
|
||||
GROUP BY SUBSTR(mgclear_time_t, 1, 4), province_t
|
||||
) a LEFT JOIN (
|
||||
SELECT
|
||||
perYear,
|
||||
SUM(order_amt) AS all_order_count
|
||||
FROM (SELECT SUBSTR(mgclear_time, 1, 4) AS perYear, province, COUNT(DISTINCT platform_order_no) AS order_amt
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30' AND province <> ''
|
||||
GROUP BY SUBSTR(mgclear_time, 1, 4), province
|
||||
) GROUP BY perYear
|
||||
) b ON a.perYear = b.perYear
|
||||
ORDER BY a.perYear, a.goodsAmt + a.orderFreightAmt DESC;
|
||||
|
||||
-- 考虑同一订单号多个店铺情况
|
||||
--SELECT
|
||||
-- a.perYear AS "年份",
|
||||
-- a.province_t AS "省份",
|
||||
-- a.goodsAmt AS "销售金额(元)",
|
||||
-- a.orderFreightAmt AS "运费金额(元)",
|
||||
-- a.goodsAmt + a.orderFreightAmt AS "销售金额(元)(包含运费)",
|
||||
-- a.order_amt AS "订单数量",
|
||||
-- b.all_order_count AS "订单总数量",
|
||||
-- ROUND((a.sale_amount + a.freight_amount) / b.all_order_count, 2) AS "订单占比"
|
||||
--FROM (SELECT
|
||||
-- perYear,
|
||||
-- province_t,
|
||||
-- SUM(goods_amt_t_t) AS goodsAmt,
|
||||
-- xxx
|
||||
-- FROM (SELECT
|
||||
-- SUBSTR(mgclear_time_t, 1, 4) AS perYear,
|
||||
-- store_code,
|
||||
-- province_t,
|
||||
-- SUM(goods_amt_t) AS goods_amt_t_t,
|
||||
-- SUM(order_freight_amt_t) AS order_freight_amt_t_t,
|
||||
-- COUNT(DISTINCT platform_order_no) AS order_amt_t
|
||||
-- FROM (SELECT
|
||||
-- store_code,
|
||||
-- MAX(store_name) AS store_name_t,
|
||||
-- system_order_no,
|
||||
-- platform_order_no,
|
||||
-- MIN(mgclear_time) AS mgclear_time_t,
|
||||
-- MAX(order_freight_amt) AS order_freight_amt_t,
|
||||
-- SUM(goods_qty) AS goods_qty_t,
|
||||
-- SUM(goods_amt) AS goods_amt_t,
|
||||
-- MAX(province) AS province_t
|
||||
-- FROM custom_online_sale_order_local
|
||||
-- GROUP BY store_code, system_order_no, platform_order_no
|
||||
-- )
|
||||
-- WHERE mgclear_time_t <> '' AND SUBSTR(mgclear_time_t, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time_t, 1, 10) <= '2025-06-30'
|
||||
-- GROUP BY SUBSTR(mgclear_time_t, 1, 4), store_code, province_t
|
||||
-- ) GROUP BY perYear, province_t
|
||||
--) a
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 2.2线上每年各等级城市销售金额、订单数量及其占比
|
||||
-- 城市为空 -> 其他
|
||||
-- 省直辖县级行政区 -> 区域替换城市(其他区和空也直接换)
|
||||
-- 湖北省直辖县 -> 区域替换城市(其它区也直接换)
|
||||
-- 县 -> 省份替换城市
|
||||
-- 自治区直辖县级行政区划 -> 区域替换城市
|
||||
-- 省直辖县级行政区划 -> 区域替换城市(其他区和空也直接换)
|
||||
-- 新疆维吾尔自治区直辖县 -> 区域替换城市
|
||||
-- 维吾尔自治区 -> 区域替换城市
|
||||
-- 河南省直辖县 -> 区域替换城市
|
||||
-- 市辖区 -> 省份替换城市
|
||||
-- 广东 -> 区域替换城市
|
||||
-- 湖北 -> 区域替换城市
|
||||
SELECT city, COUNT() FROM custom_online_sale_order_local GROUP BY city;
|
||||
|
||||
SELECT DISTINCT region FROM custom_online_sale_order_local WHERE city = '省直辖县级行政区';
|
||||
SELECT * FROM custom_online_sale_order_local WHERE city = '省直辖县级行政区' AND region = '';
|
||||
SELECT * FROM custom_online_sale_order_local WHERE city = '省直辖县级行政区' AND region = '其它区';
|
||||
|
||||
SELECT DISTINCT region FROM custom_online_sale_order_local WHERE city = '湖北省直辖县';
|
||||
|
||||
SELECT DISTINCT province FROM custom_online_sale_order_local WHERE city = '县';
|
||||
|
||||
SELECT * FROM custom_online_sale_order_local WHERE city = '自治区直辖县级行政区划';
|
||||
|
||||
SELECT DISTINCT region FROM custom_online_sale_order_local WHERE city = '省直辖县级行政区划';
|
||||
SELECT * FROM custom_online_sale_order_local WHERE city = '省直辖县级行政区划' AND region = '';
|
||||
SELECT * FROM custom_online_sale_order_local WHERE city = '省直辖县级行政区划' AND region = '其它区';
|
||||
|
||||
SELECT * FROM custom_online_sale_order_local WHERE city = '新疆维吾尔自治区直辖县';
|
||||
|
||||
SELECT * FROM custom_online_sale_order_local WHERE city = '维吾尔自治区';
|
||||
|
||||
SELECT * FROM custom_online_sale_order_local WHERE city = '河南省直辖县';
|
||||
|
||||
SELECT * FROM custom_online_sale_order_local WHERE city = '市辖区';
|
||||
|
||||
SELECT * FROM custom_online_sale_order_local WHERE city = '广东';
|
||||
|
||||
SELECT * FROM custom_online_sale_order_local WHERE city = '湖北';
|
||||
|
||||
-- 1236382条平台订单没有城市
|
||||
SELECT source_system, COUNT(DISTINCT platform_order_no) FROM custom_online_sale_order_local WHERE city = '' GROUP BY source_system;
|
||||
-- 城市和等级关联到的只有5695单 需要手工调整
|
||||
SELECT DISTINCT city FROM custom_online_sale_order_local;
|
||||
-- 只能计算有订单的,账单的不能算(没有城市)
|
||||
-- 忽略城市为空的平台订单
|
||||
SELECT
|
||||
a.perYear AS "年份",
|
||||
a.city_grade_t AS "城市等级",
|
||||
a.goodsAmt AS "销售金额(元)",
|
||||
a.orderFreightAmt AS "运费金额(元)",
|
||||
a.goodsAmt + a.orderFreightAmt AS "销售金额(元)(包含运费)",
|
||||
a.order_amt AS "订单数量",
|
||||
b.all_order_count AS "订单总数量",
|
||||
ROUND((a.goodsAmt + a.orderFreightAmt) / b.all_order_count, 2) AS "订单占比"
|
||||
FROM (SELECT
|
||||
SUBSTR(mgclear_time_t, 1, 4) AS perYear,
|
||||
city_grade_t,
|
||||
SUM(goods_amt_t) AS goodsAmt,
|
||||
SUM(order_freight_amt_t) AS orderFreightAmt,
|
||||
COUNT(DISTINCT platform_order_no) AS order_amt
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
MAX(store_name) AS store_name_t,
|
||||
system_order_no,
|
||||
platform_order_no,
|
||||
MIN(mgclear_time) AS mgclear_time_t,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t,
|
||||
SUM(goods_qty) AS goods_qty_t,
|
||||
SUM(goods_amt) AS goods_amt_t,
|
||||
MAX(t2.city_grade) AS city_grade_t
|
||||
FROM custom_online_sale_order_local t1
|
||||
LEFT JOIN custom_online_city_grade_local t2 ON t1.city = t2.city
|
||||
WHERE mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30' AND t2.city_grade <> ''
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
)
|
||||
GROUP BY SUBSTR(mgclear_time_t, 1, 4), city_grade_t
|
||||
) a LEFT JOIN (
|
||||
SELECT
|
||||
perYear,
|
||||
SUM(order_amt) AS all_order_count
|
||||
FROM (SELECT SUBSTR(mgclear_time, 1, 4) AS perYear, t2.city_grade, COUNT(DISTINCT platform_order_no) AS order_amt
|
||||
FROM custom_online_sale_order_local t1
|
||||
LEFT JOIN custom_online_city_grade_local t2 ON t1.city = t2.city
|
||||
WHERE mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30' AND t2.city_grade <> ''
|
||||
GROUP BY SUBSTR(mgclear_time, 1, 4), t2.city_grade
|
||||
) GROUP BY perYear
|
||||
) b ON a.perYear = b.perYear
|
||||
ORDER BY a.perYear, a.goodsAmt + a.orderFreightAmt DESC;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 3.1线上每年单笔订单金额分布及其占比
|
||||
|
||||
-- xxxxxxxxxxxxxxxxx
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 3.2线上每年同一个收货地址的地址数量、销售金额、订单数量
|
||||
-- 100053条
|
||||
SELECT platform_order_no FROM custom_online_sale_order_local GROUP BY platform_order_no HAVING COUNT(DISTINCT consignee_add) > 1;
|
||||
SELECT * FROM custom_online_sale_order_local WHERE platform_order_no = '4920083542368856013A';
|
||||
-- SBZ换货没有标识 | 换货单或者手工单发货地址为明文,与平台是一个地址,但是平台属于密文,只取一个
|
||||
-- 1869294条平台订单没有收货地址,账单的都没有
|
||||
SELECT
|
||||
SUBSTR(mgclear_time_t, 1, 4) AS "年份",
|
||||
consignee_add_t AS "收货地址",
|
||||
SUM(goods_amt_t) AS "销售金额(元)",
|
||||
SUM(order_freight_amt_t) AS "运费金额(元)",
|
||||
SUM(goods_amt_t) + SUM(order_freight_amt_t) AS "销售金额(元)(包含运费)",
|
||||
COUNT(DISTINCT platform_order_no) AS "订单数量"
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
MAX(store_name) AS store_name_t,
|
||||
system_order_no,
|
||||
platform_order_no,
|
||||
MIN(mgclear_time) AS mgclear_time_t,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t,
|
||||
SUM(goods_qty) AS goods_qty_t,
|
||||
SUM(goods_amt) AS goods_amt_t,
|
||||
MAX(consignee_add) AS consignee_add_t
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30' AND consignee_add <> ''
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
)
|
||||
GROUP BY SUBSTR(mgclear_time_t, 1, 4), consignee_add_t
|
||||
ORDER BY SUBSTR(mgclear_time_t, 1, 4), SUM(goods_amt_t) + SUM(order_freight_amt_t) DESC;
|
||||
|
||||
-- 省份+地址
|
||||
--SELECT COUNT() FROM custom_online_sale_order_local WHERE consignee_add = ''; -- 1869294
|
||||
--SELECT COUNT() FROM custom_online_sale_order_local WHERE province = ''; -- 1869251
|
||||
--SELECT COUNT() FROM custom_online_sale_order_local WHERE consignee_add = '' AND province = ''; -- 1869249
|
||||
--
|
||||
--SELECT
|
||||
-- SUBSTR(mgclear_time_t, 1, 4) AS "年份",
|
||||
-- consignee_add_t AS "收货地址",
|
||||
-- SUM(goods_amt_t) AS "销售金额(元)",
|
||||
-- SUM(order_freight_amt_t) AS "运费金额(元)",
|
||||
-- SUM(goods_amt_t) + SUM(order_freight_amt_t) AS "销售金额(元)(包含运费)",
|
||||
-- COUNT(DISTINCT platform_order_no) AS "订单数量"
|
||||
--FROM (SELECT
|
||||
-- store_code,
|
||||
-- MAX(store_name) AS store_name_t,
|
||||
-- system_order_no,
|
||||
-- platform_order_no,
|
||||
-- MIN(mgclear_time) AS mgclear_time_t,
|
||||
-- MAX(order_freight_amt) AS order_freight_amt_t,
|
||||
-- SUM(goods_qty) AS goods_qty_t,
|
||||
-- SUM(goods_amt) AS goods_amt_t,
|
||||
-- CONCAT(MAX(province), MAX(consignee_add)) AS consignee_add_t
|
||||
-- FROM custom_online_sale_order_local
|
||||
-- WHERE mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30' AND consignee_add <> ''
|
||||
-- GROUP BY store_code, system_order_no, platform_order_no
|
||||
--)
|
||||
--GROUP BY SUBSTR(mgclear_time_t, 1, 4), consignee_add_t
|
||||
--ORDER BY SUBSTR(mgclear_time_t, 1, 4), SUM(goods_amt_t) + SUM(order_freight_amt_t) DESC;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 3.3线上每年各天和各小时订单数量和销售金额
|
||||
-- mgclear_time没有时分秒的数量 28669 SBZE3的部分单子 计算各小时的需要去除,时间为空的1792612
|
||||
SELECT * FROM custom_online_sale_order_local WHERE mgclear_time <> '' AND LENGTH(mgclear_time) <= 10;
|
||||
-- 账单mgclear_time没有时分秒的数量 0 ,时间为空的5093196
|
||||
SELECT COUNT() FROM custom_online_sale_bill_local WHERE mgclear_time = '' ;
|
||||
SELECT COUNT() FROM custom_online_sale_bill_local WHERE mgclear_time <> '' AND LENGTH(mgclear_time) <= 10;
|
||||
-- 账单的不能算订单数量
|
||||
SELECT
|
||||
SUBSTR(mgclear_time_t, 1, 4) AS "年份",
|
||||
SUBSTR(mgclear_time_t, 6, 5) AS "日期",
|
||||
SUM(goods_amt_t) AS "销售金额(元)",
|
||||
SUM(order_freight_amt_t) AS "运费金额(元)",
|
||||
SUM(goods_amt_t) + SUM(order_freight_amt_t) AS "销售金额(元)(包含运费)",
|
||||
COUNT(DISTINCT platform_order_no) AS "订单数量"
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
MAX(store_name) AS store_name_t,
|
||||
system_order_no,
|
||||
platform_order_no,
|
||||
MIN(mgclear_time) AS mgclear_time_t,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t,
|
||||
SUM(goods_qty) AS goods_qty_t,
|
||||
SUM(goods_amt) AS goods_amt_t
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30'
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
)
|
||||
GROUP BY SUBSTR(mgclear_time_t, 1, 4), SUBSTR(mgclear_time_t, 6, 5)
|
||||
ORDER BY SUBSTR(mgclear_time_t, 1, 4), SUM(goods_amt_t) + SUM(order_freight_amt_t) DESC;
|
||||
|
||||
-- 账单店铺金额
|
||||
SELECT
|
||||
SUBSTR(mgclear_time, 1, 4) AS "年份",
|
||||
SUBSTR(mgclear_time, 6, 5) AS "日期",
|
||||
SUM(goods_amt) AS "销售金额(元)"
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt >= 0 AND mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30'
|
||||
GROUP BY SUBSTR(mgclear_time, 1, 4), SUBSTR(mgclear_time, 6, 5)
|
||||
ORDER BY SUBSTR(mgclear_time, 1, 4), SUM(goods_amt) DESC;
|
||||
|
||||
|
||||
-- 按照小时算 ----------
|
||||
SELECT
|
||||
SUBSTR(mgclear_time_t, 1, 4) AS "年份",
|
||||
time_area AS "时间区间",
|
||||
SUM(goods_amt_t) AS "销售金额(元)",
|
||||
SUM(order_freight_amt_t) AS "运费金额(元)",
|
||||
SUM(goods_amt_t) + SUM(order_freight_amt_t) AS "销售金额(元)(包含运费)",
|
||||
COUNT(DISTINCT platform_order_no) AS "订单数量"
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
MAX(store_name) AS store_name_t,
|
||||
system_order_no,
|
||||
platform_order_no,
|
||||
MIN(mgclear_time) AS mgclear_time_t,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t,
|
||||
SUM(goods_qty) AS goods_qty_t,
|
||||
SUM(goods_amt) AS goods_amt_t,
|
||||
CASE WHEN LENGTH(mgclear_time_t) > 10 THEN
|
||||
CASE
|
||||
WHEN toInt32(SUBSTR(mgclear_time_t, 12, 2)) = 0 THEN '0-1点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time_t, 12, 2)) = 1 THEN '1-2点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time_t, 12, 2)) = 2 THEN '2-3点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time_t, 12, 2)) = 3 THEN '3-4点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time_t, 12, 2)) = 4 THEN '4-5点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time_t, 12, 2)) = 5 THEN '5-6点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time_t, 12, 2)) = 6 THEN '6-7点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time_t, 12, 2)) = 7 THEN '7-8点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time_t, 12, 2)) = 8 THEN '8-9点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time_t, 12, 2)) = 9 THEN '9-10点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time_t, 12, 2)) = 10 THEN '10-11点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time_t, 12, 2)) = 11 THEN '11-12点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time_t, 12, 2)) = 12 THEN '12-13点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time_t, 12, 2)) = 13 THEN '13-14点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time_t, 12, 2)) = 14 THEN '14-15点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time_t, 12, 2)) = 15 THEN '15-16点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time_t, 12, 2)) = 16 THEN '16-17点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time_t, 12, 2)) = 17 THEN '17-18点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time_t, 12, 2)) = 18 THEN '18-19点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time_t, 12, 2)) = 19 THEN '19-20点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time_t, 12, 2)) = 20 THEN '20-21点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time_t, 12, 2)) = 21 THEN '21-22点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time_t, 12, 2)) = 22 THEN '22-23点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time_t, 12, 2)) = 23 THEN '23-24点'
|
||||
END
|
||||
ELSE '其他' END AS time_area
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30'
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
)
|
||||
WHERE time_area <> '其他'
|
||||
GROUP BY SUBSTR(mgclear_time_t, 1, 4), time_area
|
||||
ORDER BY SUBSTR(mgclear_time_t, 1, 4), SUM(goods_amt_t) + SUM(order_freight_amt_t) DESC;
|
||||
|
||||
-- 账单店铺金额
|
||||
-- 22 23年没有带时间的
|
||||
SELECT
|
||||
SUBSTR(mgclear_time, 1, 4) AS "年份",
|
||||
time_area AS "时间区间",
|
||||
SUM(goods_amt) AS "销售金额(元)"
|
||||
FROM (SELECT
|
||||
mgclear_time,
|
||||
CASE
|
||||
WHEN toInt32(SUBSTR(mgclear_time, 12, 2)) = 0 THEN '0-1点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time, 12, 2)) = 1 THEN '1-2点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time, 12, 2)) = 2 THEN '2-3点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time, 12, 2)) = 3 THEN '3-4点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time, 12, 2)) = 4 THEN '4-5点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time, 12, 2)) = 5 THEN '5-6点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time, 12, 2)) = 6 THEN '6-7点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time, 12, 2)) = 7 THEN '7-8点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time, 12, 2)) = 8 THEN '8-9点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time, 12, 2)) = 9 THEN '9-10点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time, 12, 2)) = 10 THEN '10-11点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time, 12, 2)) = 11 THEN '11-12点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time, 12, 2)) = 12 THEN '12-13点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time, 12, 2)) = 13 THEN '13-14点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time, 12, 2)) = 14 THEN '14-15点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time, 12, 2)) = 15 THEN '15-16点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time, 12, 2)) = 16 THEN '16-17点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time, 12, 2)) = 17 THEN '17-18点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time, 12, 2)) = 18 THEN '18-19点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time, 12, 2)) = 19 THEN '19-20点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time, 12, 2)) = 20 THEN '20-21点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time, 12, 2)) = 21 THEN '21-22点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time, 12, 2)) = 22 THEN '22-23点'
|
||||
WHEN toInt32(SUBSTR(mgclear_time, 12, 2)) = 23 THEN '23-24点'
|
||||
END AS time_area,
|
||||
goods_amt
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt >= 0 AND mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30' AND LENGTH(mgclear_time) > 10
|
||||
) GROUP BY SUBSTR(mgclear_time, 1, 4), time_area
|
||||
ORDER BY SUBSTR(mgclear_time, 1, 4), SUM(goods_amt) DESC;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 3.4线上每年大促期间店铺销售金额、订单数量和占比
|
||||
|
||||
-- xxxxxxxxxxxxxxxxx
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 4.1线上每年订单下单和发货间隔的销售金额、订单数量分布
|
||||
|
||||
-- xxxxxxxxxxxxxxxxx
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 4.2线上每年各物流承运商销售金额、订单数量
|
||||
-- 932303条平台订单物流承运商为空 账单的为SBZ 40条财务手工单,无平台订单号不考虑
|
||||
SELECT COUNT(DISTINCT platform_order_no) FROM custom_online_sale_order_local WHERE carrier = '';
|
||||
|
||||
SELECT carrier, COUNT(DISTINCT platform_order_no) FROM custom_online_sale_order_local GROUP BY carrier;
|
||||
|
||||
SELECT
|
||||
SUBSTR(mgclear_time_t, 1, 4) AS "年份",
|
||||
carrierName AS "承运商",
|
||||
SUM(goods_amt_t) AS "销售金额(元)",
|
||||
SUM(order_freight_amt_t) AS "运费金额(元)",
|
||||
SUM(goods_amt_t) + SUM(order_freight_amt_t) AS "销售金额(元)(包含运费)",
|
||||
COUNT(DISTINCT platform_order_no) AS "订单数量"
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
MAX(store_name) AS store_name_t,
|
||||
system_order_no,
|
||||
platform_order_no,
|
||||
MIN(mgclear_time) AS mgclear_time_t,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t,
|
||||
SUM(goods_qty) AS goods_qty_t,
|
||||
SUM(goods_amt) AS goods_amt_t,
|
||||
MAX(carrier) AS carrier_t,
|
||||
CASE
|
||||
WHEN carrier_t IN ('shunfeng') OR carrier_t LIKE 'sf%' OR carrier_t LIKE 'SF%' OR carrier_t LIKE '顺丰%' THEN '顺丰'
|
||||
WHEN carrier_t IN ('postb', 'eyb') OR carrier_t LIKE 'ems%' OR carrier_t LIKE 'EMS%' THEN '邮政'
|
||||
WHEN carrier_t LIKE 'yunda%' OR carrier_t LIKE 'YUNDA%' THEN '韵达'
|
||||
WHEN carrier_t IN ('ZT') OR carrier_t LIKE 'zto%' OR carrier_t LIKE 'ZTO%' OR carrier_t LIKE '中通%' THEN '中通'
|
||||
WHEN carrier_t LIKE 'jd%' OR carrier_t LIKE 'JD%' OR carrier_t LIKE '京东%' THEN '京东'
|
||||
WHEN carrier_t IN ('ST#DW', 'ST') OR carrier_t LIKE 'sto%' OR carrier_t LIKE 'STO%' OR carrier_t LIKE '申通%' THEN '申通'
|
||||
WHEN carrier_t LIKE 'jt%' OR carrier_t LIKE 'JT%' THEN '极兔'
|
||||
WHEN carrier_t IN ('YT') OR carrier_t LIKE 'yto%' OR carrier_t LIKE 'YTO%' OR carrier_t LIKE '圆通%' THEN '圆通'
|
||||
WHEN carrier_t IN ('rider') THEN '骑士'
|
||||
WHEN carrier_t IN ('dbl') THEN '德邦'
|
||||
WHEN carrier_t IN ('htky') THEN '汇通'
|
||||
WHEN carrier_t IN ('QSKD') THEN '千顺'
|
||||
WHEN carrier_t IN ('fengwang') THEN '丰网'
|
||||
WHEN carrier_t IN ('best') THEN '百世'
|
||||
WHEN carrier_t IN ('ttkdex') THEN '天天'
|
||||
ELSE carrier_t
|
||||
END AS carrierName
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30'
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
)
|
||||
GROUP BY SUBSTR(mgclear_time_t, 1, 4), carrierName
|
||||
ORDER BY SUBSTR(mgclear_time_t, 1, 4), SUM(goods_amt_t) + SUM(order_freight_amt_t) DESC;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 4.3线上每年各月物流单数量
|
||||
-- 按照最小下单时间,物流单往前归
|
||||
SELECT
|
||||
SUBSTR(mgclear_time, 1, 4) AS "年份",
|
||||
SUBSTR(mgclear_time, 6, 2) AS "月份",
|
||||
COUNT(DISTINCT main_logistic_bill) AS "物流单数量"
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30' AND main_logistic_bill <> ''
|
||||
GROUP BY SUBSTR(mgclear_time, 1, 4), SUBSTR(mgclear_time, 6, 2)
|
||||
ORDER BY SUBSTR(mgclear_time, 1, 4), SUBSTR(mgclear_time, 6, 2);
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 5.1线上各店铺每年度退款金额
|
||||
-- 账单有没有和退款中重复的?????????????
|
||||
-- 1200609条平台订单号为空
|
||||
SELECT COUNT() FROM custom_online_sale_return_local WHERE platform_order_no = '';
|
||||
-- 没有
|
||||
SELECT * FROM custom_online_sale_return_local WHERE platform_order_no <> '' AND platform_order_no IN (SELECT platform_order_no FROM custom_online_sale_bill_local);
|
||||
-- 593条 DYE2 SF00891-19条
|
||||
SELECT * FROM custom_online_sale_return_local WHERE store_code IN (SELECT store_code FROM custom_online_sale_bill_local);
|
||||
-- 1299161
|
||||
SELECT * FROM custom_online_sale_return_local WHERE mgclear_time = '';
|
||||
-- 换货的退款不区分 退款订单数量识别不出来,合并发货的平台单A,B,C只退B,退款平台单号也是A,B,C
|
||||
SELECT
|
||||
SUBSTR(mgclear_time_t, 1, 4) AS "年份",
|
||||
store_code AS "店铺编码",
|
||||
MAX(store_name_t) AS "店铺名称",
|
||||
SUM(return_goods_amt_t) AS "退款金额(元)",
|
||||
SUM(return_freight_amt_t) AS "退款运费金额(元)",
|
||||
SUM(return_goods_amt_t) + SUM(return_freight_amt_t) AS "退款金额(元)(包含退款运费)"
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
MAX(store_name) AS store_name_t,
|
||||
system_order_no,
|
||||
platform_order_no,
|
||||
MIN(mgclear_time) AS mgclear_time_t,
|
||||
MAX(return_freight_amt) AS return_freight_amt_t,
|
||||
SUM(return_goods_qty) AS return_goods_qty_t,
|
||||
SUM(return_goods_amt) AS return_goods_amt_t
|
||||
FROM custom_online_sale_return_local
|
||||
WHERE mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30'
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
)
|
||||
GROUP BY SUBSTR(mgclear_time_t, 1, 4), store_code
|
||||
ORDER BY SUBSTR(mgclear_time_t, 1, 4), SUM(return_goods_amt_t) + SUM(return_freight_amt_t);
|
||||
|
||||
-- 账单店铺金额
|
||||
SELECT
|
||||
SUBSTR(mgclear_time, 1, 4) AS "年份",
|
||||
store_code AS "店铺编码",
|
||||
MAX(store_name) AS "店铺名称",
|
||||
SUM(goods_amt) AS "退款金额(元)"
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt < 0 AND mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30'
|
||||
GROUP BY SUBSTR(mgclear_time, 1, 4), store_code
|
||||
ORDER BY SUBSTR(mgclear_time, 1, 4), SUM(goods_amt);
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 5.2线上各店铺每年退款订单数量
|
||||
|
||||
-- xxxxxxxxxxxxxxxxx
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 5.3线上每年退款大于原销售的差异金额、订单数量
|
||||
|
||||
-- xxxxxxxxxxxxxxxxx
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 5.4线上每年各月退款金额
|
||||
SELECT
|
||||
SUBSTR(mgclear_time_t, 1, 4) AS "年份",
|
||||
SUBSTR(mgclear_time_t, 6, 2) AS "月份",
|
||||
SUM(return_goods_amt_t) AS "退款金额(元)",
|
||||
SUM(return_freight_amt_t) AS "退款运费金额(元)",
|
||||
SUM(return_goods_amt_t) + SUM(return_freight_amt_t) AS "退款金额(元)(包含退款运费)"
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
MAX(store_name) AS store_name_t,
|
||||
system_order_no,
|
||||
platform_order_no,
|
||||
MIN(mgclear_time) AS mgclear_time_t,
|
||||
MAX(return_freight_amt) AS return_freight_amt_t,
|
||||
SUM(return_goods_qty) AS return_goods_qty_t,
|
||||
SUM(return_goods_amt) AS return_goods_amt_t
|
||||
FROM custom_online_sale_return_local
|
||||
WHERE mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30'
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
)
|
||||
GROUP BY SUBSTR(mgclear_time_t, 1, 4), SUBSTR(mgclear_time_t, 6, 2)
|
||||
ORDER BY SUBSTR(mgclear_time_t, 1, 4), SUBSTR(mgclear_time_t, 6, 2);
|
||||
|
||||
-- 账单店铺金额
|
||||
SELECT
|
||||
SUBSTR(mgclear_time, 1, 4) AS "年份",
|
||||
SUBSTR(mgclear_time, 6, 2) AS "月份",
|
||||
SUM(goods_amt) AS "退款金额(元)"
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt < 0 AND mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30'
|
||||
GROUP BY SUBSTR(mgclear_time, 1, 4), SUBSTR(mgclear_time, 6, 2)
|
||||
ORDER BY SUBSTR(mgclear_time, 1, 4), SUBSTR(mgclear_time, 6, 2);
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 5.5线上每年各月退款订单数量
|
||||
|
||||
-- xxxxxxxxxxxxxxxxx
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 5.6线上每年订单退款金额分布
|
||||
|
||||
-- xxxxxxxxxxxxxxxxx 识别不出准确订单数量
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 6.1线上每年净销售金额前100订单净销售金额
|
||||
|
||||
-- xxxxxxxxxxxxxxxxx
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 6.2线上每年净销售金额前100订单各省份净销售金额
|
||||
|
||||
-- xxxxxxxxxxxxxxxxx
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 6.3线上每年净销售金额前100订单各商品净销售金额
|
||||
|
||||
-- xxxxxxxxxxxxxxxxx
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 7.1线上每年会员数量
|
||||
-- 19年有会员系统,所以很多没有注册门店
|
||||
SELECT brand, COUNT() FROM dwd_basic_all_vip_info_dd WHERE member_register_shop = '' GROUP BY brand ;
|
||||
SELECT SUBSTR(member_register_time, 1, 4), COUNT() FROM dwd_basic_all_vip_info_dd WHERE member_register_shop = '' AND brand = 'BES' GROUP BY SUBSTR(member_register_time, 1, 4);
|
||||
|
||||
-- 账单没有
|
||||
SELECT * FROM custom_online_sale_bill_local WHERE store_code IN (SELECT member_register_shop FROM dwd_basic_all_vip_info_dd);
|
||||
-- 3345273
|
||||
SELECT * FROM custom_online_sale_order_local WHERE store_code IN (SELECT member_register_shop FROM dwd_basic_all_vip_info_dd);
|
||||
-- 30条会员数据没有注册时间
|
||||
SELECT COUNT(DISTINCT t2.member_id)
|
||||
FROM (SELECT DISTINCT store_code FROM custom_online_sale_order_local WHERE mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30') t1
|
||||
INNER JOIN dwd_basic_all_vip_info_dd t2 ON t1.store_code = t2.member_register_shop
|
||||
WHERE t2.member_register_time = '';
|
||||
|
||||
-- 每年底数量
|
||||
SELECT
|
||||
COUNT(DISTINCT CASE WHEN SUBSTR(t2.member_register_time, 1, 4) < '2023' THEN t2.member_id END) AS count_2022,
|
||||
COUNT(DISTINCT CASE WHEN SUBSTR(t2.member_register_time, 1, 4) < '2024' THEN t2.member_id END) AS count_2023,
|
||||
COUNT(DISTINCT CASE WHEN SUBSTR(t2.member_register_time, 1, 4) < '2025' THEN t2.member_id END) AS count_2024,
|
||||
COUNT(DISTINCT CASE WHEN SUBSTR(t2.member_register_time, 1, 10) <= '2025-06-30' THEN t2.member_id END) AS count_20250630
|
||||
FROM (SELECT DISTINCT store_code FROM custom_online_sale_order_local WHERE mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30') t1
|
||||
INNER JOIN dwd_basic_all_vip_info_dd t2 ON t1.store_code = t2.member_register_shop
|
||||
WHERE t2.member_register_time <> '';
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 7.2线上每年活跃会员数量及其占比
|
||||
-- 1363725条积分变动数据变动时间为空
|
||||
SELECT COUNT() FROM dwd_basic_all_vip_point_dd WHERE change_time = '';
|
||||
--
|
||||
--SELECT t2.*
|
||||
--FROM (SELECT DISTINCT store_code FROM custom_online_sale_order_local WHERE mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30') t1
|
||||
--INNER JOIN dwd_basic_all_vip_info_dd t2 ON t1.store_code = t2.member_register_shop
|
||||
--WHERE SUBSTR(t2.member_register_time, 1, 10) <= '2025-06-30';
|
||||
|
||||
-- 订单号关联不到积分数据
|
||||
SELECT * FROM custom_online_sale_order_local WHERE platform_order_no IN (SELECT bill_no FROM dwd_basic_all_vip_point_dd WHERE bill_no <> '');
|
||||
SELECT * FROM custom_online_sale_order_local WHERE system_order_no IN (SELECT bill_no FROM dwd_basic_all_vip_point_dd WHERE bill_no <> '');
|
||||
|
||||
SELECT * FROM custom_online_sale_order_local t1 INNER JOIN dwd_basic_all_vip_point_dd t2 ON t1.system_order_no = t2.bill_no;
|
||||
SELECT * FROM custom_online_sale_order_local t1 INNER JOIN dwd_basic_all_vip_point_dd t2 ON t1.platform_order_no = t2.bill_no;
|
||||
|
||||
|
||||
SELECT
|
||||
a.perYear "年份",
|
||||
a.member_count AS "活跃会员数量",
|
||||
ROUND(a.member_count /
|
||||
CASE
|
||||
WHEN a.perYear = '2022' THEN b.count_2022
|
||||
WHEN a.perYear = '2023' THEN b.count_2023
|
||||
WHEN a.perYear = '2024' THEN b.count_2024
|
||||
WHEN a.perYear = '2025' THEN b.count_20250630
|
||||
END
|
||||
, 4) AS "活跃会员占比"
|
||||
FROM (SELECT SUBSTR(change_time, 1, 4) AS perYear, COUNT(DISTINCT member_id) AS member_count
|
||||
FROM dwd_basic_all_vip_point_dd
|
||||
WHERE member_id IN (SELECT DISTINCT member_id
|
||||
FROM (SELECT DISTINCT store_code FROM custom_online_sale_order_local WHERE mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30') t1
|
||||
INNER JOIN dwd_basic_all_vip_info_dd t2 ON t1.store_code = t2.member_register_shop
|
||||
WHERE t2.member_register_time <> '')
|
||||
AND point_change > '0' AND change_time <> '' AND SUBSTR(change_time, 1, 10) >= '2022-01-01' AND SUBSTR(change_time, 1, 10) <= '2025-06-30'
|
||||
GROUP BY SUBSTR(change_time, 1, 4)
|
||||
) a, (
|
||||
SELECT
|
||||
COUNT(DISTINCT CASE WHEN SUBSTR(t2.member_register_time, 1, 4) < '2023' THEN t2.member_id END) AS count_2022,
|
||||
COUNT(DISTINCT CASE WHEN SUBSTR(t2.member_register_time, 1, 4) < '2024' THEN t2.member_id END) AS count_2023,
|
||||
COUNT(DISTINCT CASE WHEN SUBSTR(t2.member_register_time, 1, 4) < '2025' THEN t2.member_id END) AS count_2024,
|
||||
COUNT(DISTINCT CASE WHEN SUBSTR(t2.member_register_time, 1, 10) <= '2025-06-30' THEN t2.member_id END) AS count_20250630
|
||||
FROM (SELECT DISTINCT store_code FROM custom_online_sale_order_local WHERE mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30') t1
|
||||
INNER JOIN dwd_basic_all_vip_info_dd t2 ON t1.store_code = t2.member_register_shop
|
||||
WHERE t2.member_register_time <> ''
|
||||
) b
|
||||
ORDER BY a.perYear;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 7.3线上每年会员新增、注销数量
|
||||
|
||||
|
||||
-- 每年新增
|
||||
SELECT SUBSTR(t2.member_register_time, 1, 4), COUNT(DISTINCT t2.member_id)
|
||||
FROM (SELECT DISTINCT store_code FROM custom_online_sale_order_local WHERE mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30') t1
|
||||
INNER JOIN dwd_basic_all_vip_info_dd t2 ON t1.store_code = t2.member_register_shop
|
||||
WHERE t2.member_register_time <> '' AND SUBSTR(t2.member_register_time, 1, 10) <= '2025-06-30'
|
||||
GROUP BY SUBSTR(t2.member_register_time, 1, 4)
|
||||
ORDER BY SUBSTR(t2.member_register_time, 1, 4);
|
||||
|
||||
-- 注销没数据
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 7.4线上每年会员积分新增、消耗、清零数量
|
||||
-- 积分类型
|
||||
SELECT DISTINCT change_kind FROM dwd_basic_all_vip_point_dd;
|
||||
-- 积分清零有大于0的
|
||||
SELECT * FROM dwd_basic_all_vip_point_dd WHERE change_kind = '60' AND point_change > '0';
|
||||
|
||||
-- 正向积分 获取
|
||||
SELECT SUBSTR(change_time, 1, 4) AS perYear, SUM(toDecimal64(point_change, 2))
|
||||
FROM dwd_basic_all_vip_point_dd
|
||||
WHERE member_id IN (SELECT DISTINCT member_id
|
||||
FROM (SELECT DISTINCT store_code FROM custom_online_sale_order_local
|
||||
WHERE mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30') t1
|
||||
INNER JOIN dwd_basic_all_vip_info_dd t2 ON t1.store_code = t2.member_register_shop
|
||||
WHERE t2.member_register_time <> '')
|
||||
AND point_change > '0' AND change_time <> '' AND SUBSTR(change_time, 1, 10) >= '2022-01-01' AND SUBSTR(change_time, 1, 10) <= '2025-06-30' AND change_kind <> '60'
|
||||
GROUP BY SUBSTR(change_time, 1, 4)
|
||||
ORDER BY SUBSTR(change_time, 1, 4);
|
||||
-- 逆向积分 消耗
|
||||
SELECT SUBSTR(change_time, 1, 4) AS perYear, SUM(toDecimal64(point_change, 2))
|
||||
FROM dwd_basic_all_vip_point_dd
|
||||
WHERE member_id IN (SELECT DISTINCT member_id
|
||||
FROM (SELECT DISTINCT store_code FROM custom_online_sale_order_local
|
||||
WHERE mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30') t1
|
||||
INNER JOIN dwd_basic_all_vip_info_dd t2 ON t1.store_code = t2.member_register_shop
|
||||
WHERE t2.member_register_time <> '')
|
||||
AND point_change < '0' AND change_time <> '' AND SUBSTR(change_time, 1, 10) >= '2022-01-01' AND SUBSTR(change_time, 1, 10) <= '2025-06-30' AND change_kind <> '60'
|
||||
GROUP BY SUBSTR(change_time, 1, 4)
|
||||
ORDER BY SUBSTR(change_time, 1, 4);
|
||||
-- 积分清零
|
||||
SELECT SUBSTR(change_time, 1, 4) AS perYear, SUM(toDecimal64(point_change, 2))
|
||||
FROM dwd_basic_all_vip_point_dd
|
||||
WHERE member_id IN (SELECT DISTINCT member_id
|
||||
FROM (SELECT DISTINCT store_code FROM custom_online_sale_order_local
|
||||
WHERE mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) <= '2025-06-30') t1
|
||||
INNER JOIN dwd_basic_all_vip_info_dd t2 ON t1.store_code = t2.member_register_shop
|
||||
WHERE t2.member_register_time <> '')
|
||||
AND point_change < '0' AND change_time <> '' AND SUBSTR(change_time, 1, 10) >= '2022-01-01' AND SUBSTR(change_time, 1, 10) <= '2025-06-30' AND change_kind = '60'
|
||||
GROUP BY SUBSTR(change_time, 1, 4)
|
||||
ORDER BY SUBSTR(change_time, 1, 4);
|
||||
|
||||
------------------------------------------------------------------
|
664
数据分析/v3/验证.sql
Normal file
664
数据分析/v3/验证.sql
Normal file
@@ -0,0 +1,664 @@
|
||||
-- 统计系统、品牌、店铺
|
||||
SELECT DISTINCT source_system FROM dwd_trade_hkaudit_ecommerce_sale_mt;
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE source_system = 'PF_ESP';
|
||||
SELECT SUBSTR(order_date, 1, 4), brand_code FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
GROUP BY SUBSTR(order_date, 1, 4), brand_code ORDER BY SUBSTR(order_date, 1, 4);
|
||||
|
||||
SELECT SUBSTR(order_date, 1, 4), store_code, MAX(store_name) FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
GROUP BY SUBSTR(order_date, 1, 4), store_code ORDER BY SUBSTR(order_date, 1, 4);
|
||||
|
||||
SELECT COUNT(DISTINCT store_code) FROM dwd_trade_hkaudit_ecommerce_sale_mt;
|
||||
|
||||
-- 赠品有金额
|
||||
SELECT *
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE is_gift = '是' AND goods_amt > 0;
|
||||
|
||||
-- 钱货两清时间24年,支付25年
|
||||
SELECT *
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE platform_order_no = '3725079539738352640';
|
||||
SELECT source_system, brand_code , order_time , system_order_no , store_code , store_name , manual_order , is_swap_order , platform_order_no ,
|
||||
pay_time , deliver_time , mgclear_time , main_logistic_bill
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE mgclear_time < order_time AND manual_order <> '是';
|
||||
SELECT *
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE mgclear_time < order_time AND manual_order = '是' AND mgclear_time <> '';
|
||||
SELECT *
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE mgclear_time = '' AND manual_order = '是';
|
||||
|
||||
SELECT store_code , MAX(store_name), sum(goods_amt)
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE SUBSTR(mgclear_time, 1, 4) < '2022' AND brand_code NOT IN ('SBZ', 'YEO') AND order_date < '2025-07-01' AND mgclear_time <> ''
|
||||
GROUP BY store_code;
|
||||
|
||||
SELECT COUNT()
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE mgclear_time = '' AND order_date < '2025-07-01';
|
||||
SELECT brand_code, COUNT()
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE mgclear_time = ''
|
||||
GROUP BY brand_code ;
|
||||
SELECT store_code, SUBSTR(order_date, 1, 7), MAX(store_name), COUNT()
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE mgclear_time = ''
|
||||
GROUP BY store_code, SUBSTR(order_date, 1, 7);
|
||||
|
||||
SELECT source_system, brand_code, COUNT()
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE mgclear_time <> '' AND mgclear_time < order_time
|
||||
GROUP BY source_system, brand_code;
|
||||
|
||||
SELECT DISTINCT store_code
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE mgclear_time <> '' AND mgclear_time < order_time
|
||||
AND source_system = 'SBZE3';
|
||||
SELECT *
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE mgclear_time <> '' AND mgclear_time < order_time
|
||||
AND source_system = 'SBZE3' AND store_code = 'SW00067';
|
||||
|
||||
SELECT source_system, brand_code
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE mgclear_time < order_time AND manual_order <> '是'
|
||||
GROUP BY source_system, brand_code;
|
||||
|
||||
|
||||
SELECT brand, COUNT() FROM dwd_basic_all_vip_info_dd WHERE member_register_shop = '' GROUP BY brand ;
|
||||
SELECT SUBSTR(member_register_time, 1, 4), COUNT() FROM dwd_basic_all_vip_info_dd WHERE member_register_shop = '' AND brand = 'BES' GROUP BY SUBSTR(member_register_time, 1, 4);
|
||||
|
||||
|
||||
-- 所有品牌
|
||||
SELECT DISTINCT brand_code
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt;
|
||||
|
||||
-- 斯博兹 京东奥莱店铺
|
||||
SELECT store_code, MAX(store_name), SUM(goods_amt)
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE store_name IN ('京东奥莱官方旗舰店', '京东奥莱秒送店')
|
||||
AND order_date >= '2024-01-01' AND order_date < '2025-07-01'
|
||||
GROUP BY store_code;
|
||||
|
||||
SELECT store_code, MAX(store_name), SUM(goods_amt)
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE brand_code = 'SBZ'
|
||||
AND order_date >= '2024-01-01' AND order_date < '2025-07-01'
|
||||
GROUP BY store_code ORDER BY SUM(goods_amt) DESC;
|
||||
|
||||
|
||||
-- 斯博兹按年月排(下单时间)
|
||||
SELECT SUBSTR(order_date, 1, 7), SUM(goods_amt)
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE brand_code = 'SBZ'
|
||||
GROUP BY SUBSTR(order_date, 1, 7)
|
||||
ORDER BY SUM(goods_amt);
|
||||
|
||||
-- 斯博兹按年月排(钱货两清时间)
|
||||
SELECT SUBSTR(mgclear_time, 1, 7), SUM(goods_amt)
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE brand_code = 'SBZ'
|
||||
GROUP BY SUBSTR(mgclear_time, 1, 7)
|
||||
ORDER BY SUM(goods_amt);
|
||||
|
||||
-- 各品牌钱货两清时间为空的按照下单时间统计
|
||||
SELECT brand_code, SUBSTR(order_time, 1, 7), COUNT()
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE mgclear_time IS NULL OR mgclear_time = ''
|
||||
GROUP BY brand_code, SUBSTR(order_time, 1, 7);
|
||||
|
||||
-- 订单结算金额为负的没有
|
||||
-- 订单商品结算金额为负 -1102996285.66
|
||||
SELECT SUM(goods_amt)
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE goods_amt < 0;
|
||||
-- 具体数据
|
||||
SELECT *
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE goods_amt < 0 LIMIT 1000;
|
||||
-- 按照店铺分
|
||||
SELECT store_code, MAX(store_name), SUM(goods_amt)
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE goods_amt < 0
|
||||
GROUP BY store_code;
|
||||
|
||||
-- 店铺编码对应多个名称 176家存在
|
||||
SELECT store_code, COUNT(DISTINCT store_name)
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
GROUP BY store_code HAVING COUNT(DISTINCT store_name) > 1;
|
||||
|
||||
-- 线上销售均摊金额之和是否等于订单结算金额
|
||||
SELECT a.platform_order_no, a.order_amount, b.goods_amount FROM
|
||||
(SELECT platform_order_no, MAX(order_settle_amt) AS order_amount
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE platform_order_no <> '' AND platform_order_no IS NOT NULL
|
||||
GROUP BY platform_order_no) a
|
||||
LEFT JOIN (SELECT platform_order_no, SUM(goods_amt) AS goods_amount
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
GROUP BY platform_order_no) b ON a.platform_order_no = b.platform_order_no
|
||||
WHERE a.order_amount <> b.goods_amount;
|
||||
|
||||
SELECT *
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE platform_order_no = '284444210101';
|
||||
|
||||
-- 换货单查询
|
||||
SELECT *
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE is_swap_order <> '否';
|
||||
-- 为空的 4912136
|
||||
SELECT COUNT()
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE is_swap_order = '';
|
||||
|
||||
-- 下单和发货间隔
|
||||
-- 发货时间为空的 手工单 41 总共 14193791
|
||||
SELECT
|
||||
COUNT()
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE manual_order = '是' AND deliver_time = '';
|
||||
SELECT
|
||||
COUNT()
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE deliver_time = '';
|
||||
-- 发货时间为空的数据查询
|
||||
SELECT
|
||||
store_code, MAX(store_name), COUNT()
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE deliver_time = '' AND SUBSTR(order_date, 1, 4) = '2024'
|
||||
AND store_name NOT LIKE '%唯品会%' AND store_name NOT LIKE '%京东自营%' AND brand_code <> 'SBZ'
|
||||
GROUP BY store_code ;
|
||||
-- 按店铺各月发货时间为空分布
|
||||
SELECT
|
||||
store_code, MAX(store_name), SUBSTR(order_date, 1, 7), COUNT()
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE deliver_time = '' AND store_name NOT LIKE '%唯品会%'
|
||||
GROUP BY store_code, SUBSTR(order_date, 1, 7);
|
||||
|
||||
SELECT
|
||||
store_code, MAX(store_name), source_platform , COUNT(), COUNT(DISTINCT platform_order_no), COUNT(DISTINCT system_order_no)
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE deliver_time = '' AND store_name NOT LIKE '%唯品会%'
|
||||
GROUP BY store_code, source_platform ;
|
||||
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE store_code = 'SF00242';
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE deliver_time = '' AND SUBSTR(order_date, 1, 4) = '2024' AND store_code IN ('S000001');
|
||||
-- 发货间隔 3天以上 44507 >7 30796 > 15 23021 >30 20540
|
||||
SELECT
|
||||
COUNT()
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE manual_order = '是' AND deliver_time <> '' AND dateDiff('day', toDateTime(order_time), toDateTime(deliver_time)) > 30;
|
||||
SELECT *
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE manual_order = '是' AND deliver_time <> '' AND dateDiff('day', toDateTime(order_time), toDateTime(deliver_time)) > 30;
|
||||
SELECT AVG(dateDiff('day', toDateTime(order_time), toDateTime(deliver_time)))
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE manual_order <> '是' AND deliver_time <> '';
|
||||
|
||||
|
||||
-- 粗略计算销售金额
|
||||
SELECT
|
||||
SUM(goods_amt)
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE mgclear_time <> '' AND YEAR(toDate(mgclear_time)) = '2024';
|
||||
SELECT
|
||||
SUM(return_goods_amt)
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_return_mt WHERE mgclear_time <> '' AND YEAR(toDate(mgclear_time)) = '2024';
|
||||
SELECT
|
||||
SUM(special_barcode_amt)
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_change_mt WHERE mgclear_time <> '' AND YEAR(toDate(mgclear_time)) = '2024';
|
||||
|
||||
-- 每个店铺每年收入情况
|
||||
-- 不同店铺相同订单号 802
|
||||
SELECT platform_order_no
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
GROUP BY platform_order_no HAVING COUNT(DISTINCT store_code) > 1;
|
||||
|
||||
SELECT *
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE platform_order_no = '4155933925640151503';
|
||||
-- 带入店铺算
|
||||
SELECT a.perYear, a.store_code, MAX(a.store_name), SUM(a.sale_amount), SUM(b.sale_refund_amount), SUM(c.sale_change_amount)
|
||||
FROM (SELECT
|
||||
SUBSTR(order_date, 1, 4) AS perYear,
|
||||
store_code,
|
||||
MAX(store_name) AS store_name,
|
||||
platform_order_no,
|
||||
SUM(goods_amt) AS sale_amount
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
--WHERE SUBSTR(order_date, 1, 4) = '2024'
|
||||
GROUP BY SUBSTR(order_date, 1, 4), store_code, platform_order_no) a
|
||||
LEFT JOIN (
|
||||
SELECT store_code, platform_order_no, SUM(return_goods_amt) AS sale_refund_amount
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_return_mt
|
||||
GROUP BY store_code, platform_order_no
|
||||
) b ON a.store_code = b.store_code AND a.platform_order_no = b.platform_order_no
|
||||
LEFT JOIN (
|
||||
SELECT store_code, platform_order_no, SUM(special_barcode_amt) AS sale_change_amount
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_change_mt
|
||||
GROUP BY store_code, platform_order_no
|
||||
) c ON a.store_code = c.store_code AND a.platform_order_no = c.platform_order_no
|
||||
GROUP BY a.perYear, a.store_code;
|
||||
|
||||
SELECT a.perYear, a.store_code, MAX(a.store_name), SUM(a.sale_amount), SUM(b.sale_refund_amount), SUM(c.sale_change_amount)
|
||||
FROM (SELECT
|
||||
SUBSTR(order_date, 1, 4) AS perYear,
|
||||
store_code,
|
||||
MAX(store_name) AS store_name,
|
||||
platform_order_no,
|
||||
SUM(goods_amt) AS sale_amount
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE order_date >= '2025-01-01' AND order_date < '2025-07-01'
|
||||
GROUP BY SUBSTR(order_date, 1, 4), store_code, platform_order_no) a
|
||||
LEFT JOIN (
|
||||
SELECT store_code, platform_order_no, SUM(return_goods_amt) AS sale_refund_amount
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_return_mt
|
||||
GROUP BY store_code, platform_order_no
|
||||
) b ON a.store_code = b.store_code AND a.platform_order_no = b.platform_order_no
|
||||
LEFT JOIN (
|
||||
SELECT store_code, platform_order_no, SUM(special_barcode_amt) AS sale_change_amount
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_change_mt
|
||||
GROUP BY store_code, platform_order_no
|
||||
) c ON a.store_code = c.store_code AND a.platform_order_no = c.platform_order_no
|
||||
GROUP BY a.perYear, a.store_code;
|
||||
|
||||
SELECT a.perYear, a.store_code, MAX(a.store_name), SUM(a.sale_amount), SUM(b.sale_refund_amount), SUM(c.sale_change_amount)
|
||||
FROM (SELECT
|
||||
SUBSTR(order_date, 1, 4) AS perYear,
|
||||
store_code,
|
||||
MAX(store_name) AS store_name,
|
||||
platform_order_no,
|
||||
SUM(goods_amt) AS sale_amount
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE SUBSTR(order_date, 1, 4) = '2024' AND store_code = 'DHF3'
|
||||
GROUP BY SUBSTR(order_date, 1, 4), store_code, platform_order_no) a
|
||||
LEFT JOIN (
|
||||
SELECT store_code, platform_order_no, SUM(return_goods_amt) AS sale_refund_amount
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_return_mt
|
||||
GROUP BY store_code, platform_order_no
|
||||
) b ON a.store_code = b.store_code AND a.platform_order_no = b.platform_order_no
|
||||
LEFT JOIN (
|
||||
SELECT store_code, platform_order_no, SUM(special_barcode_amt) AS sale_change_amount
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_change_mt
|
||||
GROUP BY store_code, platform_order_no
|
||||
) c ON a.store_code = c.store_code AND a.platform_order_no = c.platform_order_no
|
||||
GROUP BY a.perYear, a.store_code;
|
||||
|
||||
-- 发货调整数量不为0的
|
||||
SELECT *
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_change_mt
|
||||
WHERE goods_qty <> 0 AND SUBSTR(create_date, 1, 4) = '2023';
|
||||
|
||||
SELECT *
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_change_mt
|
||||
WHERE system_order_no = 'BS513100011188';
|
||||
|
||||
-- 销售有负数 退销有正数
|
||||
SELECT source_system, COUNT() FROM
|
||||
dwd_trade_hkaudit_ecommerce_sale_mt WHERE goods_amt < 0
|
||||
GROUP BY source_system ;
|
||||
SELECT MAX(source_system) , store_code, MAX(store_name), COUNT() FROM
|
||||
dwd_trade_hkaudit_ecommerce_sale_mt WHERE goods_amt < 0
|
||||
GROUP BY store_code ;
|
||||
|
||||
SELECT COUNT()
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_return_mt
|
||||
WHERE return_goods_amt > 0;
|
||||
|
||||
SELECT *
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_return_mt
|
||||
WHERE system_order_no = 'BS210100000263';
|
||||
|
||||
SELECT source_system, COUNT() FROM
|
||||
dwd_trade_hkaudit_ecommerce_sale_mt WHERE system_order_no LIKE 'FHTZ%'
|
||||
GROUP BY source_system;
|
||||
|
||||
SELECT DISTINCT store_name
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE source_system = 'PF_ECP';
|
||||
|
||||
-- 订单重复行计算 140579734
|
||||
SELECT COUNT(DISTINCT *) FROM dwd_trade_hkaudit_ecommerce_sale_mt;
|
||||
-- 145002782
|
||||
SELECT COUNT() FROM dwd_trade_hkaudit_ecommerce_sale_mt;
|
||||
-- 取数查看
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE system_order_no IN (
|
||||
SELECT system_order_no FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE system_order_no IN (
|
||||
SELECT system_order_no
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE source_system = 'E3PLUS_NEW'
|
||||
GROUP BY system_order_no, platform_order_no, goods_barcode, goods_amt
|
||||
HAVING COUNT() > 1
|
||||
)
|
||||
GROUP BY system_order_no HAVING MAX(order_settle_amt) < SUM(goods_amt)
|
||||
) ORDER BY system_order_no DESC;
|
||||
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE system_order_no = 'BS4A0300002724';
|
||||
|
||||
-- 退销平台单号查看(是否和销售单号关联)
|
||||
SELECT SUM(platform_order_num)
|
||||
FROM (SELECT store_code, COUNT(DISTINCT platform_order_no) AS platform_order_num
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_return_mt WHERE SUBSTR(create_time, 1, 10) >= '2025-01-01' AND SUBSTR(create_time, 1, 10) < '2025-07-01'
|
||||
GROUP BY store_code);
|
||||
|
||||
SELECT SUM(platform_order_num)
|
||||
FROM (
|
||||
SELECT store_code, COUNT(DISTINCT platform_order_no) AS platform_order_num
|
||||
FROM (SELECT *
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_return_mt
|
||||
WHERE SUBSTR(create_time, 1, 10) >= '2025-01-01' AND SUBSTR(create_time, 1, 10) < '2025-03-01' ) a
|
||||
INNER JOIN (SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE SUBSTR(order_date, 1, 4) = '2025') b ON a.store_code = b.store_code AND a.platform_order_no = b.platform_order_no
|
||||
GROUP BY store_code
|
||||
);
|
||||
|
||||
SELECT source_platform, store_code, MAX(store_name), SUM(goods_amt)
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
GROUP BY source_platform, store_code ORDER BY SUM(goods_amt) DESC;
|
||||
|
||||
-- 账单:BS3B1900003767 BS392000041139
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_account_mt dtheam WHERE bill_source = '1' AND SUBSTR(transaction_date, 1, 4) = '2024' AND matching_status = '1';
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_account_mt dtheam WHERE matching_no = 'BS3923R0002529';
|
||||
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt dthesm WHERE platform_order_no LIKE '%231119-419587705691524%';
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt dthesm WHERE system_order_no = 'BS392000041139';
|
||||
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_return_mt dthesrm WHERE platform_order_no LIKE '%,%';
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_return_mt dthesrm WHERE system_order_no = 'BS3923R0002529';
|
||||
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_change_mt dthescm WHERE platform_order_no IN ('231119-071838012891524,231119-419587705691524');
|
||||
|
||||
-- 18,615,790
|
||||
SELECT COUNT(DISTINCT system_order_no) FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE store_code = 'DHF3' AND mgclear_time <> '' AND is_gift <> '是';
|
||||
-- 14,621,773 14,641,473
|
||||
SELECT COUNT(DISTINCT matching_no) FROM dwd_trade_hkaudit_ecommerce_account_mt WHERE matching_no IN (
|
||||
SELECT DISTINCT system_order_no FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE store_code = 'DHF3' AND mgclear_time <> ''
|
||||
);
|
||||
--
|
||||
SELECT COUNT(DISTINCT system_order_no) FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE store_code = 'DHF3' AND mgclear_time <> '' AND is_gift <> '是' AND system_order_no IN (
|
||||
SELECT DISTINCT matching_no FROM dwd_trade_hkaudit_ecommerce_account_mt
|
||||
);
|
||||
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE store_code = 'DHF3' AND mgclear_time <> '' AND is_gift <> '是' AND system_order_no NOT IN (
|
||||
SELECT DISTINCT matching_no FROM dwd_trade_hkaudit_ecommerce_account_mt
|
||||
);
|
||||
-- TM490900000511
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_account_mt WHERE matching_no = 'TM461000000493';
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_account_mt WHERE transaction_no = '2185819176131246881';
|
||||
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE platform_order_no LIKE '%4037358494865750517%';
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE system_order_no = 'TM461000000493';
|
||||
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_return_mt WHERE association_order_no = 'TM461000000493';
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_return_mt WHERE platform_order_no LIKE '%4037358494865750517%';
|
||||
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_account_mt dtheam WHERE transaction_no = '2520559669307517693';
|
||||
|
||||
-- 两边已两清的,账单应收的
|
||||
SELECT
|
||||
SUM(a.sale_amount),
|
||||
SUM(b.sale_refund_amount),
|
||||
SUM(c.amount_sum),
|
||||
SUM(d.order_freight_amt),
|
||||
SUM(f.sale_change_amount)
|
||||
FROM (SELECT
|
||||
platform_order_no,
|
||||
SUM(goods_amt) AS sale_amount
|
||||
FROM custom_online_sale_local
|
||||
WHERE store_code = 'DHF3' AND mgclear_time <> '' AND order_date = '2024-04-13'
|
||||
GROUP BY platform_order_no) a
|
||||
LEFT JOIN (
|
||||
SELECT platform_order_no, SUM(return_goods_amt) AS sale_refund_amount
|
||||
FROM custom_online_sale_return_local
|
||||
WHERE store_code = 'DHF3'
|
||||
GROUP BY platform_order_no
|
||||
) b ON a.platform_order_no = b.platform_order_no
|
||||
LEFT JOIN (
|
||||
SELECT transaction_no, SUM(amount) AS amount_sum
|
||||
FROM dwd_trade_hkaudit_ecommerce_account_mt
|
||||
WHERE shop_code = 'DHF3' AND bill_type = '1' AND quits_status = '1'
|
||||
GROUP BY transaction_no
|
||||
) c ON a.platform_order_no = c.transaction_no
|
||||
LEFT JOIN (
|
||||
SELECT platform_order_no, SUM(order_freight_amt_t) AS order_freight_amt
|
||||
FROM (SELECT
|
||||
system_order_no,
|
||||
platform_order_no,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t
|
||||
FROM custom_online_sale_local
|
||||
WHERE store_code = 'DHF3' AND mgclear_time <> '' AND order_date = '2024-04-13' AND order_freight_amt > 0
|
||||
GROUP BY system_order_no, platform_order_no
|
||||
) GROUP BY platform_order_no
|
||||
) d ON a.platform_order_no = d.platform_order_no
|
||||
LEFT JOIN (
|
||||
SELECT platform_order_no, SUM(special_barcode_amt) AS sale_change_amount
|
||||
FROM custom_online_sale_change_local
|
||||
WHERE store_code = 'DHF3'
|
||||
GROUP BY platform_order_no
|
||||
) f ON a.platform_order_no = f.platform_order_no;
|
||||
|
||||
SELECT COUNT() FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE order_date < '2022-01-01';
|
||||
|
||||
SELECT source_system, COUNT(DISTINCT system_order_no) FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE order_date < '2022-01-01' GROUP BY source_system;
|
||||
|
||||
SELECT brand_code, COUNT(DISTINCT system_order_no) FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE order_date < '2022-01-01' AND source_system = 'E3PLUS_NEW2' GROUP BY brand_code;
|
||||
|
||||
SELECT COUNT() FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE source_system = 'EC_HIS' AND store_code = 'DHF3';
|
||||
|
||||
SELECT brand_code, SUBSTR(create_date, 1, 7), COUNT() FROM dwd_trade_hkaudit_ecommerce_sale_return_mt dthesrm WHERE platform_order_no IN (
|
||||
SELECT platform_order_no FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE mgclear_time <> '' GROUP BY platform_order_no)
|
||||
AND mgclear_time = '' AND brand_code = 'HLA' GROUP BY brand_code, SUBSTR(create_date, 1, 7) ;
|
||||
|
||||
SELECT COUNT() FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE source_system = 'SBZ' AND platform_order_no IN (
|
||||
SELECT platform_order_no FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE source_system = 'SBZ_HIS'
|
||||
);
|
||||
|
||||
|
||||
-- 结算不等于商品总额的
|
||||
SELECT * FROM
|
||||
(SELECT store_code, system_order_no, MAX(order_settle_amt) AS order_settle_amt, MAX(order_freight_amt) AS order_freight_amt
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE source_system NOT LIKE 'EC%' AND store_name NOT LIKE '%唯品会%' AND store_name NOT LIKE '%京东自营%' AND store_name NOT LIKE '%英式%'
|
||||
GROUP BY store_code, system_order_no
|
||||
) a LEFT JOIN (
|
||||
SELECT store_code, system_order_no, SUM(goods_amt) AS goods_amt
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE source_system NOT LIKE 'EC%' AND store_name NOT LIKE '%唯品会%' AND store_name NOT LIKE '%京东自营%' AND store_name NOT LIKE '%英式%'
|
||||
GROUP BY store_code, system_order_no
|
||||
) b ON a.store_code = b.store_code AND a.system_order_no = b.system_order_no
|
||||
WHERE a.order_settle_amt <> b.goods_amt ;
|
||||
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE system_order_no = '3201016386813';
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE system_order_no = '3203069261697';
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE system_order_no = 'BS282100018218';
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE platform_order_no LIKE '%235316176071%';
|
||||
|
||||
SELECT system_order_no FROM dwd_trade_hkaudit_ecommerce_sale_mt GROUP BY system_order_no HAVING MAX(order_settle_amt) <> 0 AND SUM(goods_amt) = 0;
|
||||
|
||||
|
||||
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE platform_order_no IN
|
||||
(SELECT platform_order_no FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE is_swap_order = '是' AND store_name LIKE '%京东%' AND brand_code <> 'SBZ')
|
||||
ORDER BY platform_order_no;
|
||||
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt dthesm WHERE platform_order_no = '213591262551';
|
||||
|
||||
|
||||
SELECT DISTINCT store_code , store_name FROM dim_hkaudit_store_mt WHERE brand_code = 'HLA' AND store_name LIKE '%京东%' ;
|
||||
|
||||
SELECT DISTINCT store_code, store_name FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE store_code IN (
|
||||
SELECT DISTINCT store_code FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE goods_amt < 0 AND store_name NOT LIKE '%唯品会%' AND store_name NOT LIKE '%京东自营%')
|
||||
ORDER BY platform_order_no ;
|
||||
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE store_code = 'DYQ2';
|
||||
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE goods_amt < 0 AND source_system LIKE '%E3%';
|
||||
|
||||
|
||||
SELECT source_system, COUNT() FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE platform_order_no = '' GROUP BY source_system;
|
||||
|
||||
PF_ECP_NEW2 5190094
|
||||
PF_OCP_NEW 541202
|
||||
PF_ESP_NEW 553009
|
||||
SBZE3 7648558
|
||||
PF_YEP_NEW 1079740
|
||||
|
||||
PF_ECP_NEW2 5190094
|
||||
SBZE3 5093236
|
||||
PF_OCP_NEW 541202
|
||||
PF_YEP_NEW 1079740
|
||||
PF_ESP_NEW 553009
|
||||
|
||||
SELECT SUBSTR(system_order_no, 1, 7), COUNT() FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE source_system = 'SBZE3' AND platform_order_no = '' GROUP BY SUBSTR(system_order_no, 1, 7);
|
||||
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE brand_code = 'SBZ' AND platform_order_no = '' AND system_order_no LIKE '%XSDD%';
|
||||
|
||||
|
||||
SELECT store_code FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE source_system <> 'EC_HIS_NEW' GROUP BY store_code HAVING COUNT(DISTINCT source_system) > 1 ;
|
||||
SELECT store_code, MAX(store_name), arrayStringConcat(groupArray(distinct source_system), ',') AS source_system_m FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE source_system LIKE 'PF%'
|
||||
GROUP BY store_code HAVING COUNT(DISTINCT source_system) > 1 ;
|
||||
|
||||
SELECT store_code, MAX(store_name), arrayStringConcat(groupArray(distinct source_system), ',') AS source_system_m
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE source_system LIKE 'E3P%' OR source_system = 'PF_ECP_NEW2'
|
||||
GROUP BY store_code HAVING COUNT(DISTINCT source_system) > 1 ;
|
||||
|
||||
SELECT DISTINCT source_system FROM dwd_trade_hkaudit_ecommerce_sale_return_mt WHERE store_code = 'DYE2';
|
||||
|
||||
SELECT DISTINCT source_system FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE source_system LIKE 'PF%' AND store_code = 'DYO9';
|
||||
|
||||
SELECT DISTINCT brand_code FROM dwd_trade_hkaudit_ecommerce_sale_mt;
|
||||
|
||||
|
||||
SELECT DISTINCT source_system FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE store_code = 'DYE2';
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE store_code = 'DYE2';
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE platform_order_no = '22011819700880';
|
||||
|
||||
|
||||
SELECT source_system, manual_order, COUNT() FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE mgclear_time <> '' AND mgclear_time < order_time GROUP BY source_system, manual_order ;
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE mgclear_time <> '' AND mgclear_time < order_time AND source_system = 'PF_ESP_NEW';
|
||||
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE mgclear_time <> '' AND mgclear_time < order_time AND source_system IN ('E3PLUS_NEW2','EC_HIS_NEW')
|
||||
AND dateDiff('day', toDateTime(mgclear_time), toDateTime(order_time)) > 1;
|
||||
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE deliver_time < order_time AND source_system IN ('E3PLUS_NEW2','EC_HIS_NEW')
|
||||
AND dateDiff('day', toDateTime(deliver_time), toDateTime(order_time)) > 1;
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE deliver_time < order_time AND source_system IN ('E3PLUS_NEW2','EC_HIS_NEW') AND manual_order = '';
|
||||
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE SUBSTR(order_date, 1, 4) = '2121';
|
||||
|
||||
-- 346691892 , 246212129
|
||||
SELECT * FROM dwd_basic_all_vip_info_dd dbavid WHERE member_register_shop = '';
|
||||
SELECT * FROM dwd_basic_all_vip_info_dd WHERE member_id IN (SELECT member_id FROM dwd_basic_all_vip_info_dd GROUP BY member_id HAVING COUNT() > 1) ORDER BY member_id ;
|
||||
|
||||
SELECT * FROM dwd_basic_all_vip_info_dd WHERE member_register_shop = '' AND brand = 'HLA' ORDER BY member_register_time desc;
|
||||
|
||||
SELECT bill_no, COUNT() FROM dwd_basic_all_vip_point_dd dbavid GROUP BY bill_no HAVING COUNT() > 1 order by COUNT() DESC;
|
||||
|
||||
SELECT * FROM dwd_basic_all_vip_point_dd dbavid WHERE bill_no = '01H3HP2311120001';
|
||||
SELECT * FROM dwd_basic_all_vip_point_dd dbavid WHERE bill_no = '01H3HP2311120001';
|
||||
SELECT * FROM dwd_basic_all_vip_point_dd dbavid WHERE bill_no LIKE 'BS%';
|
||||
|
||||
SELECT DISTINCT substr(system_order_no, 1, 2) FROM dwd_trade_hkaudit_ecommerce_sale_return_mt WHERE source_system = 'SBZE3';
|
||||
SELECT DISTINCT substr(system_order_no, 1, 4) FROM dwd_trade_hkaudit_ecommerce_sale_return_mt WHERE source_system = 'SBZE3' AND substr(system_order_no, 1, 2) IN ('XS', 'JX');
|
||||
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_return_mt WHERE substr(system_order_no, 1, 5) = 'XSJSD';
|
||||
|
||||
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE platform_order_no = '';
|
||||
|
||||
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_return_mt WHERE source_system = 'SBZE3' AND create_date = '2025-03-28' AND return_goods_code = 'JP98143.5';
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE source_system = 'SBZE3' AND order_date = '2025-03-28' AND goods_qty < 0;
|
||||
|
||||
SELECT COUNT() FROM dwd_trade_hkaudit_ecommerce_sale_return_mt WHERE source_system = 'SBZE3' AND SUBSTR(system_order_no, 1, 5) = 'XSJSD' AND return_goods_qty < 0;
|
||||
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt dthesm WHERE SUBSTR(order_date, 1, 4) > '2100';
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE system_order_no = '12012533354151';
|
||||
|
||||
SELECT COUNT() FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE source_system LIKE 'PF%' AND SUBSTR(order_time, 1, 4) < '2022';
|
||||
|
||||
SELECT DISTINCT store_name FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE store_name LIKE '%微商城%';
|
||||
|
||||
-- 闭店还有单子产生吗
|
||||
-- 相差时间间隔
|
||||
|
||||
|
||||
SELECT store_code, brand_code, COUNT(DISTINCT system_order_no), SUM(order_settle_amt_t)
|
||||
FROM (SELECT store_code, brand_code, system_order_no, MAX(order_settle_amt) AS order_settle_amt_t FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE source_system LIKE 'E3PLUS%' AND mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) < '2025-07-01'
|
||||
GROUP BY store_code, brand_code, system_order_no
|
||||
) GROUP BY store_code, brand_code
|
||||
ORDER BY brand_code, store_code;
|
||||
|
||||
SELECT store_code, brand_code, COUNT(DISTINCT system_order_no), SUM(order_settle_amt_t)
|
||||
FROM (SELECT store_code, brand_code, system_order_no, MAX(order_settle_amt) AS order_settle_amt_t FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE source_system LIKE 'E3PLUS%' AND SUBSTR(order_time, 1, 10) < '2025-07-01'
|
||||
GROUP BY store_code, brand_code, system_order_no
|
||||
) GROUP BY store_code, brand_code
|
||||
ORDER BY brand_code, store_code;
|
||||
|
||||
SELECT DISTINCT system_order_no FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE store_code = 'DHZQ' AND source_system LIKE 'E3PLUS%' AND SUBSTR(order_time, 1, 10) < '2025-07-01';
|
||||
|
||||
SELECT store_code, brand_code, COUNT(DISTINCT system_order_no), SUM(return_goods_amt_t)
|
||||
FROM (SELECT store_code, brand_code, system_order_no, SUM(return_goods_amt) AS return_goods_amt_t FROM dwd_trade_hkaudit_ecommerce_sale_return_mt
|
||||
WHERE source_system LIKE 'E3PLUS%' AND SUBSTR(create_time, 1, 10) < '2025-07-01'
|
||||
GROUP BY store_code, brand_code, system_order_no
|
||||
) GROUP BY store_code, brand_code
|
||||
ORDER BY brand_code, store_code;
|
||||
|
||||
-- EC
|
||||
SELECT store_code, brand_code, COUNT(DISTINCT system_order_no), SUM(order_settle_amt_t)
|
||||
FROM (SELECT store_code, brand_code, system_order_no, MAX(order_settle_amt) AS order_settle_amt_t FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE source_system LIKE 'EC%' AND mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) < '2025-07-01'
|
||||
GROUP BY store_code, brand_code, system_order_no
|
||||
) GROUP BY store_code, brand_code
|
||||
ORDER BY brand_code, store_code;
|
||||
|
||||
SELECT store_code, brand_code, COUNT(DISTINCT system_order_no), SUM(return_goods_amt_t)
|
||||
FROM (SELECT store_code, brand_code, system_order_no, SUM(return_goods_amt) AS return_goods_amt_t FROM dwd_trade_hkaudit_ecommerce_sale_return_mt
|
||||
WHERE source_system LIKE 'EC%' AND mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) < '2025-07-01'
|
||||
GROUP BY store_code, brand_code, system_order_no
|
||||
) GROUP BY store_code, brand_code
|
||||
ORDER BY brand_code, store_code;
|
||||
|
||||
SELECT store_code, brand_code, COUNT(DISTINCT system_order_no), SUM(special_barcode_amt_t)
|
||||
FROM (SELECT store_code, brand_code, system_order_no, SUM(special_barcode_amt) AS special_barcode_amt_t FROM dwd_trade_hkaudit_ecommerce_sale_change_mt
|
||||
WHERE source_system LIKE 'EC%%' AND mgclear_time <> '' AND SUBSTR(mgclear_time, 1, 10) >= '2022-01-01' AND SUBSTR(mgclear_time, 1, 10) < '2025-07-01'
|
||||
GROUP BY store_code, brand_code, system_order_no
|
||||
) GROUP BY store_code, brand_code
|
||||
ORDER BY brand_code, store_code;
|
||||
|
||||
-- 钱货两清为空的
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE source_system LIKE 'SBZ_HIS%' AND mgclear_time = '';
|
||||
|
||||
SELECT DISTINCT store_code, store_name FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE brand_code = 'VPG';
|
||||
|
||||
-- 缺少门店数据
|
||||
SELECT DISTINCT brand_code, store_code FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE store_code NOT IN (SELECT store_code FROM dim_hkaudit_store_other_mt);
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE store_code IN (SELECT supplier_code FROM dim_hkaudit_ecgoods_distribution_price_mt);
|
||||
|
||||
|
||||
SELECT goods_code FROM dim_hkaudit_ecgoods_distribution_price_mt GROUP BY goods_code HAVING COUNT(DISTINCT distribution_price) > 1;
|
||||
|
||||
|
||||
SELECT DISTINCT goods_barcode FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE goods_barcode NOT IN (SELECT barcode FROM dim_hkaudit_goods_mt);
|
||||
|
||||
SELECT source_system, COUNT() FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE mgclear_time = '' GROUP BY source_system ;
|
||||
SELECT brand_code, COUNT() FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE mgclear_time = '' AND source_system = 'E3PLUS_NEW2' GROUP BY brand_code, ;
|
||||
SELECT brand_code, MAX(store_name) , COUNT(DISTINCT platform_order_no) FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE mgclear_time = '' AND source_system = 'E3PLUS_NEW2' GROUP BY brand_code;
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE mgclear_time = '' AND source_system = 'E3PLUS_NEW2' AND brand_code = 'HLA' ORDER BY order_date ;
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE mgclear_time = '' AND source_system = 'SBZE3_NEW' AND order_date <= '2025-06-30' ORDER BY order_date ;
|
||||
|
||||
SELECT dateDiff('minute', toDateTime('2025-06-30 12:00:00'), toDateTime('2025-06-30'));
|
||||
|
||||
SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE system_order_no = '3203069261697';
|
BIN
数据分析/报告/框架/海澜之家集团股份有限公司2025年数据分析报告框架.docx
Normal file
BIN
数据分析/报告/框架/海澜之家集团股份有限公司2025年数据分析报告框架.docx
Normal file
Binary file not shown.
BIN
数据分析/线下店铺/前期沟通/线上线下抽样店铺销售数据.xlsx
Normal file
BIN
数据分析/线下店铺/前期沟通/线上线下抽样店铺销售数据.xlsx
Normal file
Binary file not shown.
BIN
数据分析/线下店铺/前期沟通/线下店铺加盟联营抽样统计.xlsx
Normal file
BIN
数据分析/线下店铺/前期沟通/线下店铺加盟联营抽样统计.xlsx
Normal file
Binary file not shown.
BIN
数据核查/报告/框架/海澜之家集团股份有限公司2025年信息系统核查报告框架.docx
Normal file
BIN
数据核查/报告/框架/海澜之家集团股份有限公司2025年信息系统核查报告框架.docx
Normal file
Binary file not shown.
BIN
需求/取数需求-IT.xlsx
Normal file
BIN
需求/取数需求-IT.xlsx
Normal file
Binary file not shown.
BIN
需求/审计资料需求清单-财务.xlsx
Normal file
BIN
需求/审计资料需求清单-财务.xlsx
Normal file
Binary file not shown.
188
预处理.sql
Normal file
188
预处理.sql
Normal file
@@ -0,0 +1,188 @@
|
||||
-- 数据拆分
|
||||
SELECT
|
||||
m_new AS m, -- 拆分后的m字段
|
||||
(if(i < k, quotient, quotient + remainder)) / 100.0 AS n, -- 金额(无尾差)
|
||||
if(i > (k - t_remainder), t_div + 1, t_div) AS t -- 数量(无尾差)
|
||||
FROM (
|
||||
SELECT
|
||||
splitByChar(',', m) AS m_array, -- 拆分m为数组
|
||||
arrayEnumerate(m_array) AS i, -- 数组索引(从1开始)
|
||||
n,
|
||||
t,
|
||||
arrayLength(m_array) AS k, -- 拆分后的记录数
|
||||
toDecimal32(n * 100, 0) AS n_cents, -- 金额转分(整数)
|
||||
(toDecimal32(n * 100, 0) div k) AS quotient, -- 金额商(每份基础值)
|
||||
(toDecimal32(n * 100, 0) % k) AS remainder, -- 金额余数(最后一行补足)
|
||||
(t div k) AS t_div, -- 数量商(每份基础值)
|
||||
(t % k) AS t_remainder -- 数量余数(最后t_remainder行补足)
|
||||
FROM A
|
||||
)
|
||||
ARRAY JOIN m_array AS m_new; -- 展开数组为多行
|
||||
|
||||
|
||||
-- 退款运费金额是否有数据:有销才有退
|
||||
SELECT COUNT()
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_return_mt
|
||||
WHERE return_freight_amt > 0;
|
||||
|
||||
SELECT
|
||||
source_system,
|
||||
create_date,
|
||||
system_order_no,
|
||||
store_code,
|
||||
store_name,
|
||||
association_order_no,
|
||||
source_platform,
|
||||
platform_order_no,
|
||||
return_freight_amt
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_return_mt
|
||||
WHERE return_freight_amt > 0 LIMIT 1000;
|
||||
|
||||
-- 赠品是否有金额
|
||||
SELECT COUNT()
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE is_gift = 1 AND goods_amt > 0;
|
||||
|
||||
SELECT
|
||||
source_system,
|
||||
order_date,
|
||||
system_order_no,
|
||||
store_code,
|
||||
store_name,
|
||||
manual_order,
|
||||
is_swap_order,
|
||||
source_platform,
|
||||
platform_order_no
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE is_gift = 1 AND goods_amt > 0;
|
||||
|
||||
SELECT
|
||||
source_system,
|
||||
order_date,
|
||||
system_order_no,
|
||||
store_code,
|
||||
store_name,
|
||||
manual_order,
|
||||
is_swap_order,
|
||||
source_platform,
|
||||
platform_order_no
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE platform_order_no = '';
|
||||
|
||||
|
||||
-- 店铺编码对应多个名称
|
||||
|
||||
|
||||
-- 仅退款 在调整单处理,是否有大额的就是全退的
|
||||
|
||||
|
||||
-- 调整单和退销单的平台订单号是否和销售表一致(针对合单的)
|
||||
SELECT
|
||||
source_system,
|
||||
order_date,
|
||||
system_order_no,
|
||||
store_code,
|
||||
store_name,
|
||||
manual_order,
|
||||
is_swap_order,
|
||||
source_platform,
|
||||
platform_order_no
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE platform_order_no LIKE '%,%' LIMIT 1000;
|
||||
|
||||
SELECT
|
||||
source_system,
|
||||
order_date,
|
||||
system_order_no,
|
||||
store_code,
|
||||
store_name,
|
||||
source_platform,
|
||||
platform_order_no
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_change_mt
|
||||
WHERE platform_order_no = '';
|
||||
|
||||
|
||||
SELECT
|
||||
source_system,
|
||||
order_date,
|
||||
system_order_no,
|
||||
store_code,
|
||||
store_name,
|
||||
source_platform,
|
||||
platform_order_no
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_change_mt
|
||||
WHERE platform_order_no IN (
|
||||
SELECT
|
||||
platform_order_no
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE platform_order_no LIKE '%,%' LIMIT 1000
|
||||
);
|
||||
|
||||
-- 是否换货单字段
|
||||
SELECT
|
||||
source_system,
|
||||
order_date,
|
||||
system_order_no,
|
||||
store_code,
|
||||
store_name,
|
||||
manual_order,
|
||||
is_swap_order,
|
||||
source_platform,
|
||||
platform_order_no
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE is_swap_order IS NOT NULL LIMIT 1000;
|
||||
|
||||
|
||||
-- 斯博兹最早下单时间
|
||||
|
||||
|
||||
-- 线下订单和小票行数是否一致
|
||||
|
||||
|
||||
-- 线下支付是否一对多
|
||||
|
||||
-- 线上2024年收入 209.6亿
|
||||
-- 以钱货两清时间计算下
|
||||
SELECT SUM(order_settle_amt) FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE YEAR(mgclear_date) = '2024';
|
||||
|
||||
SELECT SUM(return_goods_amt) FROM dwd_trade_hkaudit_ecommerce_sale_return_mt WHERE platform_order_no
|
||||
IN (SELECT DISTINCT platform_order_no FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE YEAR(mgclear_date) = '2024');
|
||||
|
||||
SELECT SUM(special_barcode_amt) FROM dwd_trade_hkaudit_ecommerce_sale_change_mt WHERE platform_order_no
|
||||
IN (SELECT DISTINCT platform_order_no FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE YEAR(mgclear_date) = '2024')
|
||||
|
||||
|
||||
-- 线上销售均摊金额之和是否等于订单结算金额
|
||||
SELECT
|
||||
platform_order_no
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
GROUP BY platform_order_no HAVING SUM(goods_amt) <> MAX(order_settle_amt);
|
||||
|
||||
|
||||
-- 销售时间调整
|
||||
SELECT
|
||||
COUNT()
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE dateDiff('day', toDateTime(order_date), toDateTime(deliver_date)) > 3;
|
||||
|
||||
SELECT
|
||||
source_system,
|
||||
order_date,
|
||||
system_order_no,
|
||||
store_code,
|
||||
store_name,
|
||||
manual_order,
|
||||
is_swap_order,
|
||||
source_platform,
|
||||
platform_order_no,
|
||||
pay_date,
|
||||
deliver_date,
|
||||
mgclear_date
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE manual_order IS NOT NULL AND dateDiff('day', toDateTime(order_date), toDateTime(deliver_date)) > 3;
|
||||
|
||||
SELECT
|
||||
dateDiff('day', toDateTime(order_date), toDateTime(deliver_date)), COUNT(DISTINCT source_platform)
|
||||
FROM dwd_trade_hkaudit_ecommerce_sale_mt
|
||||
WHERE manual_order IS NULL
|
||||
GROUP BY dateDiff('day', toDateTime(order_date), toDateTime(deliver_date));
|
Reference in New Issue
Block a user