1
This commit is contained in:
@@ -277,11 +277,15 @@ FROM (SELECT
|
||||
GROUP BY t1.perYear, t1.goods_barcode
|
||||
ORDER BY t1.perYear, SUM(t1.goods_amt) DESC;
|
||||
|
||||
--SELECT * FROM custom_online_sale_bill_local WHERE goods_barcode = '000000009918000001';
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 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;
|
||||
SELECT brand_code, COUNT() FROM custom_online_sale_order_local WHERE province = '' AND source_system = 'E3PLUS_NEW2' GROUP BY brand_code ;
|
||||
SELECT brand_code, COUNT() FROM custom_online_sale_order_local WHERE source_system = 'E3PLUS_NEW2' GROUP BY brand_code ;
|
||||
-- 只能计算有订单的,账单的不能算(没有省份)
|
||||
-- 考虑店铺单号重复问题 非换货单有946单重复,加上换货单有1229条重复
|
||||
-- 忽略省份为空的平台订单
|
||||
@@ -415,7 +419,7 @@ 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单 需要手工调整
|
||||
-- 城市和等级关联到的只有5695单 需要手工调整 已调整
|
||||
SELECT DISTINCT city FROM custom_online_sale_order_local;
|
||||
-- 只能计算有订单的,账单的不能算(没有城市)
|
||||
-- 忽略城市为空的平台订单
|
||||
@@ -664,38 +668,407 @@ ORDER BY SUBSTR(order_time, 1, 4), SUM(goods_amt) DESC;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 3.4线上每年大促期间店铺销售金额、订单数量和占比
|
||||
/*
|
||||
* 2022:
|
||||
* 618: 0531-0620
|
||||
* 1111: 1031-1111
|
||||
* 2023:
|
||||
* 618: 0531-0620
|
||||
* 1111: 1020-1111
|
||||
* 2024:
|
||||
* 618: 0520-0620
|
||||
* 1111: 1017-1111
|
||||
* 2025:
|
||||
* 618: 0516-0620
|
||||
* 1111: 1008-1114
|
||||
*/
|
||||
|
||||
SELECT
|
||||
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 "订单数量"
|
||||
t1.store_code AS "店铺编码",
|
||||
t1.store_name_t_t AS "店铺名称",
|
||||
t3.sale_money AS "2022年618销售金额(元)(包含运费)",
|
||||
t3.order_count AS "2022年618订单数量",
|
||||
t2.sale_money AS "2022年双11销售金额(元)(包含运费)",
|
||||
t2.order_count AS "2022年双11订单数量",
|
||||
t1.all_sale_money AS "2022年总销售金额(元)(包含运费)",
|
||||
t1.all_order_count AS "2022年总订单数量",
|
||||
CASE WHEN t1.all_sale_money = 0 THEN 0 ELSE ROUND(t3.sale_money / t1.all_sale_money, 4) END AS "2022年618销售金额占比",
|
||||
CASE WHEN t1.all_sale_money = 0 THEN 0 ELSE ROUND(t3.order_count / t1.all_order_count, 4) END AS "2022年618订单数量占比",
|
||||
CASE WHEN t1.all_sale_money = 0 THEN 0 ELSE ROUND(t2.sale_money / t1.all_sale_money, 4) END AS "2022年双11销售金额占比",
|
||||
CASE WHEN t1.all_sale_money = 0 THEN 0 ELSE ROUND(t2.order_count / t1.all_order_count, 4) END AS "2022年双11订单数量占比"
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
MAX(store_name) AS store_name_t,
|
||||
system_order_no,
|
||||
platform_order_no,
|
||||
MIN(min_order_time) AS order_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 SUBSTR(min_order_time, 1, 10) >= '2022-06-01' AND SUBSTR(min_order_time, 1, 10) <= '2022-06-30'
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
)
|
||||
GROUP BY store_code
|
||||
ORDER BY SUM(goods_amt_t) + SUM(order_freight_amt_t) DESC;
|
||||
MAX(store_name_t) AS store_name_t_t,
|
||||
SUM(goods_amt_t) + SUM(order_freight_amt_t) AS all_sale_money,
|
||||
COUNT(DISTINCT platform_order_no) AS all_order_count
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
MAX(store_name) AS store_name_t,
|
||||
platform_order_no,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t,
|
||||
SUM(goods_amt) AS goods_amt_t
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE SUBSTR(min_order_time, 1, 10) >= '2022-01-01' AND SUBSTR(min_order_time, 1, 10) <= '2022-12-31'
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
) GROUP BY store_code
|
||||
) t1 LEFT JOIN (SELECT
|
||||
store_code,
|
||||
SUM(goods_amt_t) + SUM(order_freight_amt_t) AS sale_money,
|
||||
COUNT(DISTINCT platform_order_no) AS order_count
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
platform_order_no,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t,
|
||||
SUM(goods_amt) AS goods_amt_t
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE SUBSTR(min_order_time, 1, 10) >= '2022-10-31' AND SUBSTR(min_order_time, 1, 10) <= '2022-11-11'
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
) GROUP BY store_code
|
||||
) t2 ON t1.store_code = t2.store_code LEFT JOIN (
|
||||
SELECT
|
||||
store_code,
|
||||
SUM(goods_amt_t) + SUM(order_freight_amt_t) AS sale_money,
|
||||
COUNT(DISTINCT platform_order_no) AS order_count
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
platform_order_no,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t,
|
||||
SUM(goods_amt) AS goods_amt_t
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE SUBSTR(min_order_time, 1, 10) >= '2022-05-31' AND SUBSTR(min_order_time, 1, 10) <= '2022-06-20'
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
) GROUP BY store_code
|
||||
) t3 ON t1.store_code = t3.store_code
|
||||
ORDER BY t1.all_sale_money DESC;
|
||||
|
||||
SELECT
|
||||
t1.store_code AS "店铺编码",
|
||||
t1.store_name_t_t AS "店铺名称",
|
||||
t3.sale_money AS "2023年618销售金额(元)(包含运费)",
|
||||
t3.order_count AS "2023年618订单数量",
|
||||
t2.sale_money AS "2023年双11销售金额(元)(包含运费)",
|
||||
t2.order_count AS "2023年双11订单数量",
|
||||
t1.all_sale_money AS "2023年总销售金额(元)(包含运费)",
|
||||
t1.all_order_count AS "2023年总订单数量",
|
||||
CASE WHEN t1.all_sale_money = 0 THEN 0 ELSE ROUND(t3.sale_money / t1.all_sale_money, 4) END AS "2023年618销售金额占比",
|
||||
CASE WHEN t1.all_sale_money = 0 THEN 0 ELSE ROUND(t3.order_count / t1.all_order_count, 4) END AS "2023年618订单数量占比",
|
||||
CASE WHEN t1.all_sale_money = 0 THEN 0 ELSE ROUND(t2.sale_money / t1.all_sale_money, 4) END AS "2023年双11销售金额占比",
|
||||
CASE WHEN t1.all_sale_money = 0 THEN 0 ELSE ROUND(t2.order_count / t1.all_order_count, 4) END AS "2023年双11订单数量占比"
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
MAX(store_name_t) AS store_name_t_t,
|
||||
SUM(goods_amt_t) + SUM(order_freight_amt_t) AS all_sale_money,
|
||||
COUNT(DISTINCT platform_order_no) AS all_order_count
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
MAX(store_name) AS store_name_t,
|
||||
platform_order_no,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t,
|
||||
SUM(goods_amt) AS goods_amt_t
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE SUBSTR(min_order_time, 1, 10) >= '2023-01-01' AND SUBSTR(min_order_time, 1, 10) <= '2023-12-31'
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
) GROUP BY store_code
|
||||
) t1 LEFT JOIN (SELECT
|
||||
store_code,
|
||||
SUM(goods_amt_t) + SUM(order_freight_amt_t) AS sale_money,
|
||||
COUNT(DISTINCT platform_order_no) AS order_count
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
platform_order_no,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t,
|
||||
SUM(goods_amt) AS goods_amt_t
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE SUBSTR(min_order_time, 1, 10) >= '2023-10-20' AND SUBSTR(min_order_time, 1, 10) <= '2023-11-11'
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
) GROUP BY store_code
|
||||
) t2 ON t1.store_code = t2.store_code LEFT JOIN (
|
||||
SELECT
|
||||
store_code,
|
||||
SUM(goods_amt_t) + SUM(order_freight_amt_t) AS sale_money,
|
||||
COUNT(DISTINCT platform_order_no) AS order_count
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
platform_order_no,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t,
|
||||
SUM(goods_amt) AS goods_amt_t
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE SUBSTR(min_order_time, 1, 10) >= '2023-05-31' AND SUBSTR(min_order_time, 1, 10) <= '2023-06-20'
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
) GROUP BY store_code
|
||||
) t3 ON t1.store_code = t3.store_code
|
||||
ORDER BY t1.all_sale_money DESC;
|
||||
|
||||
SELECT
|
||||
t1.store_code AS "店铺编码",
|
||||
t1.store_name_t_t AS "店铺名称",
|
||||
t3.sale_money AS "2024年618销售金额(元)(包含运费)",
|
||||
t3.order_count AS "2024年618订单数量",
|
||||
t2.sale_money AS "2024年双11销售金额(元)(包含运费)",
|
||||
t2.order_count AS "2024年双11订单数量",
|
||||
t1.all_sale_money AS "2024年总销售金额(元)(包含运费)",
|
||||
t1.all_order_count AS "2024年总订单数量",
|
||||
CASE WHEN t1.all_sale_money = 0 THEN 0 ELSE ROUND(t3.sale_money / t1.all_sale_money, 4) END AS "2024年618销售金额占比",
|
||||
CASE WHEN t1.all_sale_money = 0 THEN 0 ELSE ROUND(t3.order_count / t1.all_order_count, 4) END AS "2024年618订单数量占比",
|
||||
CASE WHEN t1.all_sale_money = 0 THEN 0 ELSE ROUND(t2.sale_money / t1.all_sale_money, 4) END AS "2024年双11销售金额占比",
|
||||
CASE WHEN t1.all_sale_money = 0 THEN 0 ELSE ROUND(t2.order_count / t1.all_order_count, 4) END AS "2024年双11订单数量占比"
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
MAX(store_name_t) AS store_name_t_t,
|
||||
SUM(goods_amt_t) + SUM(order_freight_amt_t) AS all_sale_money,
|
||||
COUNT(DISTINCT platform_order_no) AS all_order_count
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
MAX(store_name) AS store_name_t,
|
||||
platform_order_no,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t,
|
||||
SUM(goods_amt) AS goods_amt_t
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE SUBSTR(min_order_time, 1, 10) >= '2024-01-01' AND SUBSTR(min_order_time, 1, 10) <= '2024-12-31'
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
) GROUP BY store_code
|
||||
) t1 LEFT JOIN (SELECT
|
||||
store_code,
|
||||
SUM(goods_amt_t) + SUM(order_freight_amt_t) AS sale_money,
|
||||
COUNT(DISTINCT platform_order_no) AS order_count
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
platform_order_no,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t,
|
||||
SUM(goods_amt) AS goods_amt_t
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE SUBSTR(min_order_time, 1, 10) >= '2024-10-17' AND SUBSTR(min_order_time, 1, 10) <= '2024-11-11'
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
) GROUP BY store_code
|
||||
) t2 ON t1.store_code = t2.store_code LEFT JOIN (
|
||||
SELECT
|
||||
store_code,
|
||||
SUM(goods_amt_t) + SUM(order_freight_amt_t) AS sale_money,
|
||||
COUNT(DISTINCT platform_order_no) AS order_count
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
platform_order_no,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t,
|
||||
SUM(goods_amt) AS goods_amt_t
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE SUBSTR(min_order_time, 1, 10) >= '2024-05-20' AND SUBSTR(min_order_time, 1, 10) <= '2024-06-20'
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
) GROUP BY store_code
|
||||
) t3 ON t1.store_code = t3.store_code
|
||||
ORDER BY t1.all_sale_money DESC;
|
||||
|
||||
SELECT
|
||||
t1.store_code AS "店铺编码",
|
||||
t1.store_name_t_t AS "店铺名称",
|
||||
t2.sale_money AS "2025年618销售金额(元)(包含运费)",
|
||||
t2.order_count AS "2025年618订单数量",
|
||||
t1.all_sale_money AS "20250630总销售金额(元)(包含运费)",
|
||||
t1.all_order_count AS "20250630总订单数量",
|
||||
CASE WHEN t1.all_sale_money = 0 THEN 0 ELSE ROUND(t2.sale_money / t1.all_sale_money, 4) END AS "到20250630·618销售金额占比",
|
||||
CASE WHEN t1.all_sale_money = 0 THEN 0 ELSE ROUND(t2.order_count / t1.all_order_count, 4) END AS "到20250630·618订单数量占比"
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
MAX(store_name_t) AS store_name_t_t,
|
||||
SUM(goods_amt_t) + SUM(order_freight_amt_t) AS all_sale_money,
|
||||
COUNT(DISTINCT platform_order_no) AS all_order_count
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
MAX(store_name) AS store_name_t,
|
||||
platform_order_no,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t,
|
||||
SUM(goods_amt) AS goods_amt_t
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE SUBSTR(min_order_time, 1, 10) >= '2025-01-01' AND SUBSTR(min_order_time, 1, 10) <= '2025-06-30'
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
) GROUP BY store_code
|
||||
) t1 LEFT JOIN (
|
||||
SELECT
|
||||
store_code,
|
||||
SUM(goods_amt_t) + SUM(order_freight_amt_t) AS sale_money,
|
||||
COUNT(DISTINCT platform_order_no) AS order_count
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
platform_order_no,
|
||||
MAX(order_freight_amt) AS order_freight_amt_t,
|
||||
SUM(goods_amt) AS goods_amt_t
|
||||
FROM custom_online_sale_order_local
|
||||
WHERE SUBSTR(min_order_time, 1, 10) >= '2025-05-16' AND SUBSTR(min_order_time, 1, 10) <= '2025-06-20'
|
||||
GROUP BY store_code, system_order_no, platform_order_no
|
||||
) GROUP BY store_code
|
||||
) t2 ON t1.store_code = t2.store_code
|
||||
ORDER BY t1.all_sale_money DESC;
|
||||
|
||||
-- 不区分店铺算总的
|
||||
--SELECT
|
||||
-- a.sale_money AS "2022年618销售金额(元)(包含运费)",
|
||||
-- a.order_count AS "2022年618订单数量",
|
||||
-- b.sale_money AS "2022年双11销售金额(元)(包含运费)",
|
||||
-- b.order_count AS "2022年双11订单数量",
|
||||
-- c.all_sale_money AS "2022年总销售金额(元)(包含运费)",
|
||||
-- c.all_order_count AS "2022年总订单数量",
|
||||
-- ROUND(a.sale_money / c.all_sale_money, 4) AS "2022年618销售金额占比",
|
||||
-- ROUND(a.order_count / c.all_order_count, 4) AS "2022年618订单数量占比",
|
||||
-- ROUND(b.sale_money / c.all_sale_money, 4) AS "2022年双11销售金额占比",
|
||||
-- ROUND(b.order_count / c.all_order_count, 4) AS "2022年双11订单数量占比"
|
||||
--FROM (SELECT
|
||||
-- SUM(sale_amt) AS sale_money,
|
||||
-- SUM(order_amt) AS order_count
|
||||
-- FROM (SELECT
|
||||
-- SUM(goods_amt_t) + SUM(order_freight_amt_t) AS sale_amt,
|
||||
-- COUNT(DISTINCT platform_order_no) AS order_amt
|
||||
-- FROM (SELECT
|
||||
-- store_code,
|
||||
-- platform_order_no,
|
||||
-- MAX(order_freight_amt) AS order_freight_amt_t,
|
||||
-- SUM(goods_amt) AS goods_amt_t
|
||||
-- FROM custom_online_sale_order_local
|
||||
-- WHERE SUBSTR(min_order_time, 1, 10) >= '2022-05-31' AND SUBSTR(min_order_time, 1, 10) <= '2022-06-20'
|
||||
-- GROUP BY store_code, system_order_no, platform_order_no
|
||||
-- ) GROUP BY store_code) -- 为了不同店铺同一平台单算多条,再包一层
|
||||
--) a, (SELECT
|
||||
-- SUM(sale_amt) AS sale_money,
|
||||
-- SUM(order_amt) AS order_count
|
||||
-- FROM (SELECT
|
||||
-- SUM(goods_amt_t) + SUM(order_freight_amt_t) AS sale_amt,
|
||||
-- COUNT(DISTINCT platform_order_no) AS order_amt
|
||||
-- FROM (SELECT
|
||||
-- store_code,
|
||||
-- platform_order_no,
|
||||
-- MAX(order_freight_amt) AS order_freight_amt_t,
|
||||
-- SUM(goods_amt) AS goods_amt_t
|
||||
-- FROM custom_online_sale_order_local
|
||||
-- WHERE SUBSTR(min_order_time, 1, 10) >= '2022-10-31' AND SUBSTR(min_order_time, 1, 10) <= '2022-11-11'
|
||||
-- GROUP BY store_code, system_order_no, platform_order_no
|
||||
-- ) GROUP BY store_code)
|
||||
--) b, (SELECT
|
||||
-- SUM(sale_amt) AS all_sale_money,
|
||||
-- SUM(order_amt) AS all_order_count
|
||||
-- FROM (SELECT
|
||||
-- SUM(goods_amt_t) + SUM(order_freight_amt_t) AS sale_amt,
|
||||
-- COUNT(DISTINCT platform_order_no) AS order_amt
|
||||
-- FROM (SELECT
|
||||
-- store_code,
|
||||
-- platform_order_no,
|
||||
-- MAX(order_freight_amt) AS order_freight_amt_t,
|
||||
-- SUM(goods_amt) AS goods_amt_t
|
||||
-- FROM custom_online_sale_order_local
|
||||
-- WHERE SUBSTR(min_order_time, 1, 10) >= '2022-01-01' AND SUBSTR(min_order_time, 1, 10) <= '2022-12-31'
|
||||
-- GROUP BY store_code, system_order_no, platform_order_no
|
||||
-- ) GROUP BY store_code)
|
||||
--) c;
|
||||
|
||||
-- 账单店铺金额
|
||||
SELECT
|
||||
store_code AS "店铺编码",
|
||||
MAX(store_name) AS "店铺名称",
|
||||
SUM(goods_amt) AS "销售金额(元)"
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt >= 0 AND SUBSTR(order_time, 1, 10) >= '2022-06-01' AND SUBSTR(order_time, 1, 10) <= '2022-06-30'
|
||||
GROUP BY store_code
|
||||
ORDER BY SUM(goods_amt) DESC;
|
||||
t1.store_code AS "店铺编码",
|
||||
t1.store_name_t AS "店铺名称",
|
||||
t3.sale_amt AS "2022年618销售金额(元)",
|
||||
t2.sale_amt AS "2022年双11销售金额(元)",
|
||||
t1.all_sale_amt AS "2022年总销售金额(元)",
|
||||
CASE WHEN t1.all_sale_amt = 0 THEN 0 ELSE ROUND(t3.sale_amt / t1.all_sale_amt, 4) END AS "2022年618销售金额占比",
|
||||
CASE WHEN t1.all_sale_amt = 0 THEN 0 ELSE ROUND(t2.sale_amt / t1.all_sale_amt, 4) END AS "2022年双11销售金额占比"
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
MAX(store_name) AS store_name_t,
|
||||
SUM(goods_amt) AS all_sale_amt
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt >= 0 AND SUBSTR(order_time, 1, 10) >= '2022-01-01' AND SUBSTR(order_time, 1, 10) <= '2022-12-31'
|
||||
GROUP BY store_code
|
||||
) t1 LEFT JOIN (SELECT
|
||||
store_code,
|
||||
SUM(goods_amt) AS sale_amt
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt >= 0 AND SUBSTR(order_time, 1, 10) >= '2022-10-31' AND SUBSTR(order_time, 1, 10) <= '2022-11-11'
|
||||
GROUP BY store_code
|
||||
) t2 ON t1.store_code = t2.store_code LEFT JOIN (SELECT
|
||||
store_code,
|
||||
SUM(goods_amt) AS sale_amt
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt >= 0 AND SUBSTR(order_time, 1, 10) >= '2022-05-31' AND SUBSTR(order_time, 1, 10) <= '2022-06-20'
|
||||
GROUP BY store_code
|
||||
) t3 ON t1.store_code = t3.store_code
|
||||
ORDER BY t1.all_sale_amt DESC;
|
||||
|
||||
SELECT
|
||||
t1.store_code AS "店铺编码",
|
||||
t1.store_name_t AS "店铺名称",
|
||||
t3.sale_amt AS "2023年618销售金额(元)",
|
||||
t2.sale_amt AS "2023年双11销售金额(元)",
|
||||
t1.all_sale_amt AS "2023年总销售金额(元)",
|
||||
CASE WHEN t1.all_sale_amt = 0 THEN 0 ELSE ROUND(t3.sale_amt / t1.all_sale_amt, 4) END AS "2023年618销售金额占比",
|
||||
CASE WHEN t1.all_sale_amt = 0 THEN 0 ELSE ROUND(t2.sale_amt / t1.all_sale_amt, 4) END AS "2023年双11销售金额占比"
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
MAX(store_name) AS store_name_t,
|
||||
SUM(goods_amt) AS all_sale_amt
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt >= 0 AND SUBSTR(order_time, 1, 10) >= '2023-01-01' AND SUBSTR(order_time, 1, 10) <= '2023-12-31'
|
||||
GROUP BY store_code
|
||||
) t1 LEFT JOIN (SELECT
|
||||
store_code,
|
||||
SUM(goods_amt) AS sale_amt
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt >= 0 AND SUBSTR(order_time, 1, 10) >= '2023-10-20' AND SUBSTR(order_time, 1, 10) <= '2023-11-11'
|
||||
GROUP BY store_code
|
||||
) t2 ON t1.store_code = t2.store_code LEFT JOIN (SELECT
|
||||
store_code,
|
||||
SUM(goods_amt) AS sale_amt
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt >= 0 AND SUBSTR(order_time, 1, 10) >= '2023-05-31' AND SUBSTR(order_time, 1, 10) <= '2023-06-20'
|
||||
GROUP BY store_code
|
||||
) t3 ON t1.store_code = t3.store_code
|
||||
ORDER BY t1.all_sale_amt DESC;
|
||||
|
||||
SELECT
|
||||
t1.store_code AS "店铺编码",
|
||||
t1.store_name_t AS "店铺名称",
|
||||
t3.sale_amt AS "2024年618销售金额(元)",
|
||||
t2.sale_amt AS "2024年双11销售金额(元)",
|
||||
t1.all_sale_amt AS "2024年总销售金额(元)",
|
||||
CASE WHEN t1.all_sale_amt = 0 THEN 0 ELSE ROUND(t3.sale_amt / t1.all_sale_amt, 4) END AS "2024年618销售金额占比",
|
||||
CASE WHEN t1.all_sale_amt = 0 THEN 0 ELSE ROUND(t2.sale_amt / t1.all_sale_amt, 4) END AS "2024年双11销售金额占比"
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
MAX(store_name) AS store_name_t,
|
||||
SUM(goods_amt) AS all_sale_amt
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt >= 0 AND SUBSTR(order_time, 1, 10) >= '2024-01-01' AND SUBSTR(order_time, 1, 10) <= '2024-12-31'
|
||||
GROUP BY store_code
|
||||
) t1 LEFT JOIN (SELECT
|
||||
store_code,
|
||||
SUM(goods_amt) AS sale_amt
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt >= 0 AND SUBSTR(order_time, 1, 10) >= '2024-10-17' AND SUBSTR(order_time, 1, 10) <= '2024-11-11'
|
||||
GROUP BY store_code
|
||||
) t2 ON t1.store_code = t2.store_code LEFT JOIN (SELECT
|
||||
store_code,
|
||||
SUM(goods_amt) AS sale_amt
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt >= 0 AND SUBSTR(order_time, 1, 10) >= '2024-05-20' AND SUBSTR(order_time, 1, 10) <= '2024-06-20'
|
||||
GROUP BY store_code
|
||||
) t3 ON t1.store_code = t3.store_code
|
||||
ORDER BY t1.all_sale_amt DESC;
|
||||
|
||||
SELECT
|
||||
t1.store_code AS "店铺编码",
|
||||
t1.store_name_t AS "店铺名称",
|
||||
t2.sale_amt AS "2025年618销售金额(元)",
|
||||
t1.all_sale_amt AS "20250630总销售金额(元)",
|
||||
CASE WHEN t1.all_sale_amt = 0 THEN 0 ELSE ROUND(t2.sale_amt / t1.all_sale_amt, 4) END AS "到20250630·618销售金额占比"
|
||||
FROM (SELECT
|
||||
store_code,
|
||||
MAX(store_name) AS store_name_t,
|
||||
SUM(goods_amt) AS all_sale_amt
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt >= 0 AND SUBSTR(order_time, 1, 10) >= '2025-01-01' AND SUBSTR(order_time, 1, 10) <= '2025-06-30'
|
||||
GROUP BY store_code
|
||||
) t1 LEFT JOIN (SELECT
|
||||
store_code,
|
||||
SUM(goods_amt) AS sale_amt
|
||||
FROM custom_online_sale_bill_local
|
||||
WHERE goods_amt >= 0 AND SUBSTR(order_time, 1, 10) >= '2025-05-16' AND SUBSTR(order_time, 1, 10) <= '2025-06-20'
|
||||
GROUP BY store_code
|
||||
) t2 ON t1.store_code = t2.store_code
|
||||
ORDER BY t1.all_sale_amt DESC;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- 4.1线上每年订单下单和发货间隔的销售金额、订单数量分布
|
||||
@@ -954,7 +1327,7 @@ 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 SUBSTR(min_order_time, 1, 10) >= '2022-01-01' AND SUBSTR(min_order_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';
|
||||
--WHERE SUBSTR(t2.member_register_ti me, 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 <> '');
|
||||
@@ -1013,5 +1386,101 @@ 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 SUBSTR(min_order_time, 1, 10) >= '2022-01-01' AND SUBSTR(min_order_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)
|
||||
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 SUBSTR(min_order_time, 1, 10) >= '2022-01-01' AND SUBSTR(min_order_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 SUBSTR(min_order_time, 1, 10) >= '2022-01-01' AND SUBSTR(min_order_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, change_kind, MAX(t2.point_change_name), SUM(toDecimal64(point_change, 2))
|
||||
--FROM dwd_basic_all_vip_point_dd t1 LEFT JOIN custom_point_change_enum_local t2 ON t1.change_kind = t2.point_change_kind
|
||||
--WHERE member_id IN (SELECT DISTINCT member_id
|
||||
-- FROM (SELECT DISTINCT store_code FROM custom_online_sale_order_local WHERE SUBSTR(min_order_time, 1, 10) >= '2022-01-01' AND SUBSTR(min_order_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), change_kind
|
||||
--ORDER BY SUBSTR(change_time, 1, 4);
|
||||
|
||||
--SELECT SUBSTR(change_time, 1, 4) AS perYear, change_kind,
|
||||
-- CASE
|
||||
-- WHEN change_kind = '1' THEN '初始积分'
|
||||
-- WHEN change_kind = '2' THEN '交易送积分-线下'
|
||||
-- WHEN change_kind = '7' THEN '交易退积分-线下'
|
||||
-- WHEN change_kind = '9' THEN '调整积分'
|
||||
-- WHEN change_kind = '13' THEN '接口赠送'
|
||||
-- WHEN change_kind = '15' THEN '第三方发独立活动扣积分'
|
||||
-- WHEN change_kind = '16' THEN '第三方活动积分类型'
|
||||
-- WHEN change_kind = '19' THEN '调整减少积分'
|
||||
-- WHEN change_kind = '20' THEN '交易基础积分'
|
||||
-- WHEN change_kind = '21' THEN '交易基础积分-退'
|
||||
-- WHEN change_kind = '22' THEN '交易活动积分'
|
||||
-- WHEN change_kind = '23' THEN '交易活动积分-退'
|
||||
-- WHEN change_kind = '30' THEN '退货'
|
||||
-- WHEN change_kind = '40' THEN '其他'
|
||||
-- WHEN change_kind = '50' THEN '交易送积分-线上商城'
|
||||
-- WHEN change_kind = '51' THEN '交易退积分-线上商城'
|
||||
-- WHEN change_kind = '52' THEN '交易送积分,三方商城,京东天猫等'
|
||||
-- WHEN change_kind = '53' THEN '交易退积分.三方商城,京东天猫等'
|
||||
-- WHEN change_kind = '54' THEN '交易送积分-线上商城'
|
||||
-- WHEN change_kind = '70' THEN '人工调增'
|
||||
-- WHEN change_kind = '80' THEN '人工调减'
|
||||
-- WHEN change_kind = '90' THEN '营销互动奖励积分'
|
||||
-- WHEN change_kind = '91' THEN '营销互动扣减积分'
|
||||
-- WHEN change_kind = '92' THEN '生日奖励积分'
|
||||
-- WHEN change_kind = '93' THEN '注册奖励积分'
|
||||
-- WHEN change_kind = '94' THEN '完善资料奖励积分'
|
||||
-- WHEN change_kind = '95' THEN '升降级奖励积分'
|
||||
-- WHEN change_kind = '96' THEN '通用事件奖励积分'
|
||||
-- WHEN change_kind = '5' THEN '积分兑换'
|
||||
-- WHEN change_kind = '6' THEN '积分抵现'
|
||||
-- WHEN change_kind = '8' THEN '积分抵现-冲正'
|
||||
-- WHEN change_kind = '10' THEN '积分抵现-退货'
|
||||
-- WHEN change_kind = '24' THEN '积分兑商品'
|
||||
-- WHEN change_kind = '25' THEN '积分兑商品-冲正'
|
||||
-- WHEN change_kind = '60' THEN '积分清零'
|
||||
-- WHEN change_kind = '97' THEN '生日奖励积分'
|
||||
-- WHEN change_kind = '98' THEN '交易基础积分'
|
||||
-- WHEN change_kind = '99' THEN '交易基础积分-退'
|
||||
-- WHEN change_kind = '100' THEN '交易基础积分'
|
||||
-- WHEN change_kind = '101' THEN '交易基础积分-退'
|
||||
-- END AS "积分变动类型值",
|
||||
-- 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 SUBSTR(min_order_time, 1, 10) >= '2022-01-01' AND SUBSTR(min_order_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), change_kind
|
||||
--ORDER BY SUBSTR(change_time, 1, 4);
|
||||
|
||||
------------------------------------------------------------------
|
Reference in New Issue
Block a user