diff --git a/数据分析/v3/正式-处理.sql b/数据分析/v3/正式-处理.sql index 1755d3e..462fad6 100644 --- a/数据分析/v3/正式-处理.sql +++ b/数据分析/v3/正式-处理.sql @@ -314,6 +314,11 @@ FROM custom_online_sale_order_tmp_local t1 LEFT JOIN ( ) t2 ON t1.store_code = t2.store_code AND t1.platform_order_no = t2.platform_order_no WHERE t1.order_time >= '2025-01-01 00:00:00'; +-- 7-5钱货两清时间小于发货时间的单子更新成发货时间???????????????? +SELECT * FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE deliver_time <> '' AND mgclear_time <> '' AND mgclear_time < deliver_time; +SELECT * FROM custom_online_sale_order_local WHERE deliver_time <> '' AND mgclear_time <> '' AND mgclear_time < deliver_time; +UPDATE custom_online_sale_order_local SET mgclear_time = deliver_time WHERE deliver_time <> '' AND mgclear_time <> '' AND mgclear_time < deliver_time; + -- 验证 SELECT * FROM custom_online_sale_order_local WHERE platform_order_no = ''; -- 1 -1 diff --git a/数据分析/v3/正式-查询-下单时间(算换货) - 副本.sql b/数据分析/v3/正式-查询-下单时间(算换货) - 副本.sql index eeb02a8..f2a4409 100644 --- a/数据分析/v3/正式-查询-下单时间(算换货) - 副本.sql +++ b/数据分析/v3/正式-查询-下单时间(算换货) - 副本.sql @@ -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); ------------------------------------------------------------------ \ No newline at end of file diff --git a/数据分析/v3/正式-查询-钱货两清时间.sql b/数据分析/v3/正式-查询-钱货两清时间.sql index 84d0761..def8491 100644 --- a/数据分析/v3/正式-查询-钱货两清时间.sql +++ b/数据分析/v3/正式-查询-钱货两清时间.sql @@ -945,5 +945,41 @@ 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); ------------------------------------------------------------------ \ No newline at end of file diff --git a/数据分析/v3/验证.sql b/数据分析/v3/验证.sql index 4be7415..9ed2eb3 100644 --- a/数据分析/v3/验证.sql +++ b/数据分析/v3/验证.sql @@ -200,6 +200,7 @@ 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) @@ -527,6 +528,12 @@ SELECT store_code FROM dwd_trade_hkaudit_ecommerce_sale_mt WHERE source_system 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; @@ -631,3 +638,27 @@ 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';