2025-10-08 15:47:05 +08:00
-- 1.1线上各店铺每年度销售金额、订单数量、订单均价
-- 数量和单价只能计算有订单的,账单的不能算
SELECT
SUBSTR ( order_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 ( 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-01-01 ' AND SUBSTR ( min_order_time , 1 , 10 ) < = ' 2025-06-30 '
GROUP BY store_code , system_order_no , platform_order_no
)
GROUP BY SUBSTR ( order_time_t , 1 , 4 ) , store_code
ORDER BY SUBSTR ( order_time_t , 1 , 4 ) , SUM ( goods_amt_t ) + SUM ( order_freight_amt_t ) 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 AND SUBSTR ( order_time , 1 , 10 ) > = ' 2022-01-01 ' AND SUBSTR ( order_time , 1 , 10 ) < = ' 2025-06-30 '
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 . orderTime , 1 , 4 ) AS " 年份 " ,
t1 . store_code AS " 店铺编码 " ,
MAX ( t1 . storeName ) AS " 店铺名称 " ,
SUM ( t1 . goodsAmt ) AS " 销售金额(元) " ,
SUM ( t1 . orderFreightAmt ) AS " 运费金额(元) " ,
SUM ( t2 . returnGoodsAmt ) AS " 退货金额(元) " ,
SUM ( t2 . returnFreightAmt ) AS " 退货运费金额(元) " ,
SUM ( t3 . orderChangeAmt ) AS " 发货调整金额(元) " ,
SUM ( t1 . goodsAmt ) + SUM ( t1 . orderFreightAmt ) + SUM ( t2 . returnGoodsAmt )
+ SUM ( t2 . returnFreightAmt ) + SUM ( t3 . orderChangeAmt ) AS " 净销售金额(元) "
FROM (
SELECT
store_code ,
MAX ( store_name_t ) AS storeName ,
platform_order_no ,
MIN ( order_time_t ) AS orderTime ,
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 ( 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-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 , platform_order_no
) t1 LEFT JOIN (
SELECT store_code , platform_order_no ,
SUM ( return_freight_amt_t ) AS returnFreightAmt ,
SUM ( return_goods_amt_t ) AS returnGoodsAmt
FROM ( SELECT
store_code ,
system_order_no ,
platform_order_no ,
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
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 ( special_barcode_amt ) AS orderChangeAmt
FROM custom_online_sale_change_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
GROUP BY SUBSTR ( t1 . orderTime , 1 , 4 ) , t1 . store_code
ORDER BY SUBSTR ( t1 . orderTime , 1 , 4 ) , SUM ( t1 . goodsAmt ) + SUM ( t1 . orderFreightAmt ) + SUM ( t2 . returnGoodsAmt )
+ SUM ( t2 . returnFreightAmt ) + SUM ( 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 ( 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 AND SUBSTR ( order_time , 1 , 10 ) > = ' 2022-01-01 ' AND SUBSTR ( order_time , 1 , 10 ) < = ' 2025-06-30 '
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 AND SUBSTR ( order_time , 1 , 10 ) > = ' 2022-01-01 ' AND SUBSTR ( order_time , 1 , 10 ) < = ' 2025-06-30 '
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 ( order_time_t , 1 , 4 ) AS " 年份 " ,
SUBSTR ( order_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 ( 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-01-01 ' AND SUBSTR ( min_order_time , 1 , 10 ) < = ' 2025-06-30 '
GROUP BY store_code , system_order_no , platform_order_no
)
GROUP BY SUBSTR ( order_time_t , 1 , 4 ) , SUBSTR ( order_time_t , 6 , 2 ) , store_code
ORDER BY SUBSTR ( order_time_t , 1 , 4 ) , store_code , SUBSTR ( order_time_t , 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 AND SUBSTR ( order_time , 1 , 10 ) > = ' 2022-01-01 ' AND SUBSTR ( order_time , 1 , 10 ) < = ' 2025-06-30 '
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线上每年各产品数量、产品销售金额
-- 订单中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(min_order_time, 1, 4) AS "年份",
-- goods_barcode AS "商品条码",
-- SUM(goods_qty) AS "商品数量",
-- SUM(goods_amt) AS "商品销售金额(元)"
- - 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 '
- - GROUP BY SUBSTR ( min_order_time , 1 , 4 ) , goods_barcode
- - ORDER BY SUBSTR ( min_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 AND SUBSTR ( order_time , 1 , 10 ) > = ' 2022-01-01 ' AND SUBSTR ( order_time , 1 , 10 ) < = ' 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(t1.min_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 SUBSTR ( t1 . min_order_time , 1 , 10 ) > = ' 2022-01-01 ' AND SUBSTR ( t1 . min_order_time , 1 , 10 ) < = ' 2025-06-30 '
- - GROUP BY SUBSTR ( t1 . min_order_time , 1 , 4 ) , t1 . goods_barcode
- - ORDER BY SUBSTR ( t1 . min_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(min_order_time, 1, 4) AS perYear,
-- goods_barcode,
-- goods_qty,
-- goods_amt
-- 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'
-- 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 AND SUBSTR(order_time, 1, 10) >= '2022-01-01' AND SUBSTR(order_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 ( min_order_time , 1 , 4 ) AS perYear ,
goods_barcode ,
goods_qty ,
goods_amt
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 '
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 AND SUBSTR ( order_time , 1 , 10 ) > = ' 2022-01-01 ' AND SUBSTR ( order_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 ;
2025-10-08 19:32:05 +08:00
- - SELECT * FROM custom_online_sale_bill_local WHERE goods_barcode = ' 000000009918000001 ' ;
2025-10-08 15:47:05 +08:00
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --
-- 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 ;
2025-10-08 19:32:05 +08:00
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 ;
2025-10-08 15:47:05 +08:00
-- 只能计算有订单的,账单的不能算(没有省份)
-- 考虑店铺单号重复问题 非换货单有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 ( order_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 ( 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 ,
MAX ( province ) AS province_t
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 ' AND province < > ' '
GROUP BY store_code , system_order_no , platform_order_no
)
GROUP BY SUBSTR ( order_time_t , 1 , 4 ) , province_t
) a LEFT JOIN (
SELECT
perYear ,
SUM ( order_amt ) AS all_order_count
FROM ( SELECT SUBSTR ( min_order_time , 1 , 4 ) AS perYear , province , COUNT ( DISTINCT platform_order_no ) AS order_amt
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 ' AND province < > ' '
GROUP BY SUBSTR ( min_order_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(order_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(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,
-- MAX(province) AS province_t
-- FROM custom_online_sale_order_local
-- GROUP BY store_code, system_order_no, platform_order_no
-- )
-- WHERE SUBSTR(order_time_t, 1, 10) >= '2022-01-01' AND SUBSTR(order_time_t, 1, 10) <= '2025-06-30'
-- GROUP BY SUBSTR(order_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 ;
2025-10-08 19:32:05 +08:00
-- 城市和等级关联到的只有5695单 需要手工调整 已调整
2025-10-08 15:47:05 +08:00
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 ( order_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 ( 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 ,
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 SUBSTR ( min_order_time , 1 , 10 ) > = ' 2022-01-01 ' AND SUBSTR ( min_order_time , 1 , 10 ) < = ' 2025-06-30 ' AND t2 . city_grade < > ' '
GROUP BY store_code , system_order_no , platform_order_no
)
GROUP BY SUBSTR ( order_time_t , 1 , 4 ) , city_grade_t
) a LEFT JOIN (
SELECT
perYear ,
SUM ( order_amt ) AS all_order_count
FROM ( SELECT SUBSTR ( min_order_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 SUBSTR ( min_order_time , 1 , 10 ) > = ' 2022-01-01 ' AND SUBSTR ( min_order_time , 1 , 10 ) < = ' 2025-06-30 ' AND t2 . city_grade < > ' '
GROUP BY SUBSTR ( min_order_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 ( order_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 ( 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 ,
MAX ( consignee_add ) AS consignee_add_t
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 ' AND consignee_add < > ' '
GROUP BY store_code , system_order_no , platform_order_no
)
GROUP BY SUBSTR ( order_time_t , 1 , 4 ) , consignee_add_t
ORDER BY SUBSTR ( order_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(order_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(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,
-- CONCAT(MAX(province), MAX(consignee_add)) AS consignee_add_t
-- 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' AND consignee_add <> ''
-- GROUP BY store_code, system_order_no, platform_order_no
- - )
- - GROUP BY SUBSTR ( order_time_t , 1 , 4 ) , consignee_add_t
- - ORDER BY SUBSTR ( order_time_t , 1 , 4 ) , SUM ( goods_amt_t ) + SUM ( order_freight_amt_t ) 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 ( order_time_t , 1 , 4 ) AS " 年份 " ,
SUBSTR ( order_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 ( 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-01-01 ' AND SUBSTR ( min_order_time , 1 , 10 ) < = ' 2025-06-30 '
GROUP BY store_code , system_order_no , platform_order_no
)
GROUP BY SUBSTR ( order_time_t , 1 , 4 ) , SUBSTR ( order_time_t , 6 , 5 )
ORDER BY SUBSTR ( order_time_t , 1 , 4 ) , SUM ( goods_amt_t ) + SUM ( order_freight_amt_t ) 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 AND SUBSTR ( order_time , 1 , 10 ) > = ' 2022-01-01 ' AND SUBSTR ( order_time , 1 , 10 ) < = ' 2025-06-30 '
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 ( order_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 ( 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 ,
CASE WHEN LENGTH ( order_time_t ) > 10 THEN
CASE
WHEN toInt32 ( SUBSTR ( order_time_t , 12 , 2 ) ) = 0 THEN ' 0-1点 '
WHEN toInt32 ( SUBSTR ( order_time_t , 12 , 2 ) ) = 1 THEN ' 1-2点 '
WHEN toInt32 ( SUBSTR ( order_time_t , 12 , 2 ) ) = 2 THEN ' 2-3点 '
WHEN toInt32 ( SUBSTR ( order_time_t , 12 , 2 ) ) = 3 THEN ' 3-4点 '
WHEN toInt32 ( SUBSTR ( order_time_t , 12 , 2 ) ) = 4 THEN ' 4-5点 '
WHEN toInt32 ( SUBSTR ( order_time_t , 12 , 2 ) ) = 5 THEN ' 5-6点 '
WHEN toInt32 ( SUBSTR ( order_time_t , 12 , 2 ) ) = 6 THEN ' 6-7点 '
WHEN toInt32 ( SUBSTR ( order_time_t , 12 , 2 ) ) = 7 THEN ' 7-8点 '
WHEN toInt32 ( SUBSTR ( order_time_t , 12 , 2 ) ) = 8 THEN ' 8-9点 '
WHEN toInt32 ( SUBSTR ( order_time_t , 12 , 2 ) ) = 9 THEN ' 9-10点 '
WHEN toInt32 ( SUBSTR ( order_time_t , 12 , 2 ) ) = 10 THEN ' 10-11点 '
WHEN toInt32 ( SUBSTR ( order_time_t , 12 , 2 ) ) = 11 THEN ' 11-12点 '
WHEN toInt32 ( SUBSTR ( order_time_t , 12 , 2 ) ) = 12 THEN ' 12-13点 '
WHEN toInt32 ( SUBSTR ( order_time_t , 12 , 2 ) ) = 13 THEN ' 13-14点 '
WHEN toInt32 ( SUBSTR ( order_time_t , 12 , 2 ) ) = 14 THEN ' 14-15点 '
WHEN toInt32 ( SUBSTR ( order_time_t , 12 , 2 ) ) = 15 THEN ' 15-16点 '
WHEN toInt32 ( SUBSTR ( order_time_t , 12 , 2 ) ) = 16 THEN ' 16-17点 '
WHEN toInt32 ( SUBSTR ( order_time_t , 12 , 2 ) ) = 17 THEN ' 17-18点 '
WHEN toInt32 ( SUBSTR ( order_time_t , 12 , 2 ) ) = 18 THEN ' 18-19点 '
WHEN toInt32 ( SUBSTR ( order_time_t , 12 , 2 ) ) = 19 THEN ' 19-20点 '
WHEN toInt32 ( SUBSTR ( order_time_t , 12 , 2 ) ) = 20 THEN ' 20-21点 '
WHEN toInt32 ( SUBSTR ( order_time_t , 12 , 2 ) ) = 21 THEN ' 21-22点 '
WHEN toInt32 ( SUBSTR ( order_time_t , 12 , 2 ) ) = 22 THEN ' 22-23点 '
WHEN toInt32 ( SUBSTR ( order_time_t , 12 , 2 ) ) = 23 THEN ' 23-24点 '
END
ELSE ' 其他 ' END AS time_area
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 '
GROUP BY store_code , system_order_no , platform_order_no
)
WHERE time_area < > ' 其他 '
GROUP BY SUBSTR ( order_time_t , 1 , 4 ) , time_area
ORDER BY SUBSTR ( order_time_t , 1 , 4 ) , SUM ( goods_amt_t ) + SUM ( order_freight_amt_t ) 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 SUBSTR ( order_time , 1 , 10 ) > = ' 2022-01-01 ' AND SUBSTR ( order_time , 1 , 10 ) < = ' 2025-06-30 ' 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线上每年大促期间店铺销售金额、订单数量和占比
2025-10-08 19:32:05 +08:00
/*
* 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
* /
2025-10-08 15:47:05 +08:00
SELECT
2025-10-08 19:32:05 +08:00
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订单数量占比 "
2025-10-08 15:47:05 +08:00
FROM ( SELECT
store_code ,
2025-10-08 19:32:05 +08:00
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 ;
2025-10-08 15:47:05 +08:00
-- 账单店铺金额
SELECT
2025-10-08 19:32:05 +08:00
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 ;
2025-10-08 15:47:05 +08:00
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --
-- 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 ( order_time_t , 1 , 4 ) AS " 年份 " ,
time_diff 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 ( 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 ,
MIN ( deliver_time ) AS deliver_time_t ,
CASE WHEN deliver_time_t < > ' ' AND order_time_t < > ' ' THEN
CASE
WHEN dateDiff ( ' minute ' , toDateTime ( deliver_time_t ) , toDateTime ( order_time_t ) ) < = 240 THEN ' 0-4小时 '
WHEN dateDiff ( ' minute ' , toDateTime ( deliver_time_t ) , toDateTime ( order_time_t ) ) > 240
AND dateDiff ( ' minute ' , toDateTime ( deliver_time_t ) , toDateTime ( order_time_t ) ) < = 1440 THEN ' 4-24小时 '
WHEN dateDiff ( ' minute ' , toDateTime ( deliver_time_t ) , toDateTime ( order_time_t ) ) > 1440
AND dateDiff ( ' minute ' , toDateTime ( deliver_time_t ) , toDateTime ( order_time_t ) ) < = 2880 THEN ' 24-48小时 '
WHEN dateDiff ( ' minute ' , toDateTime ( deliver_time_t ) , toDateTime ( order_time_t ) ) > 2880 THEN ' 大于48小时 '
END
ELSE ' 其他 '
END AS time_diff
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 '
GROUP BY store_code , system_order_no , platform_order_no
)
WHERE time_diff < > ' 其他 '
GROUP BY SUBSTR ( order_time_t , 1 , 4 ) , time_diff
ORDER BY SUBSTR ( order_time_t , 1 , 4 ) , SUM ( goods_amt_t ) + SUM ( order_freight_amt_t ) 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 ( order_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 ( 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 ,
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 SUBSTR ( min_order_time , 1 , 10 ) > = ' 2022-01-01 ' AND SUBSTR ( min_order_time , 1 , 10 ) < = ' 2025-06-30 '
GROUP BY store_code , system_order_no , platform_order_no
)
GROUP BY SUBSTR ( order_time_t , 1 , 4 ) , carrierName
ORDER BY SUBSTR ( order_time_t , 1 , 4 ) , SUM ( goods_amt_t ) + SUM ( order_freight_amt_t ) DESC ;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --
-- 4.3线上每年各月物流单数量
-- 按照最小下单时间,物流单往前归
SELECT
SUBSTR ( min_order_time , 1 , 4 ) AS " 年份 " ,
SUBSTR ( min_order_time , 6 , 2 ) AS " 月份 " ,
COUNT ( DISTINCT main_logistic_bill ) AS " 物流单数量 "
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 ' AND main_logistic_bill < > ' '
GROUP BY SUBSTR ( min_order_time , 1 , 4 ) , SUBSTR ( min_order_time , 6 , 2 )
ORDER BY SUBSTR ( min_order_time , 1 , 4 ) , SUBSTR ( min_order_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 ) ;
-- 换货的退款不区分 退款订单数量识别不出来, 合并发货的平台单A,B,C只退B, 退款平台单号也是A,B,C
SELECT
SUBSTR ( create_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 ( create_time ) AS create_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 SUBSTR ( create_time , 1 , 10 ) > = ' 2022-01-01 ' AND SUBSTR ( create_time , 1 , 10 ) < = ' 2025-06-30 '
GROUP BY store_code , system_order_no , platform_order_no
)
GROUP BY SUBSTR ( create_time_t , 1 , 4 ) , store_code
ORDER BY SUBSTR ( create_time_t , 1 , 4 ) , SUM ( return_goods_amt_t ) + SUM ( return_freight_amt_t ) ;
- - SELECT SUM ( return_goods_amt ) FROM dwd_trade_hkaudit_ecommerce_sale_return_mt WHERE SUBSTR ( create_time , 1 , 4 ) = ' 2024 ' AND store_code = ' K1817 ' ;
-- 账单店铺金额
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 AND SUBSTR ( order_time , 1 , 10 ) > = ' 2022-01-01 ' AND SUBSTR ( order_time , 1 , 10 ) < = ' 2025-06-30 '
GROUP BY SUBSTR ( order_time , 1 , 4 ) , store_code
ORDER BY SUBSTR ( order_time , 1 , 4 ) , SUM ( goods_amt ) ;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --
-- 5.2线上各店铺每年退款订单数量
-- xxxxxxxxxxxxxxxxx
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --
-- 5.3线上每年退款大于原销售的差异金额、订单数量
-- xxxxxxxxxxxxxxxxx
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --
-- 5.4线上每年各月退款金额
SELECT
SUBSTR ( create_time_t , 1 , 4 ) AS " 年份 " ,
SUBSTR ( create_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 ( create_time ) AS create_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 SUBSTR ( create_time , 1 , 10 ) > = ' 2022-01-01 ' AND SUBSTR ( create_time , 1 , 10 ) < = ' 2025-06-30 '
GROUP BY store_code , system_order_no , platform_order_no
)
GROUP BY SUBSTR ( create_time_t , 1 , 4 ) , SUBSTR ( create_time_t , 6 , 2 )
ORDER BY SUBSTR ( create_time_t , 1 , 4 ) , SUBSTR ( create_time_t , 6 , 2 ) ;
- - SELECT SUM ( return_goods_amt ) FROM dwd_trade_hkaudit_ecommerce_sale_return_mt WHERE SUBSTR ( create_time , 1 , 4 ) = ' 2024 ' AND store_code = ' K1817 ' ;
-- 账单店铺金额
SELECT
SUBSTR ( order_time , 1 , 4 ) AS " 年份 " ,
SUBSTR ( order_time , 6 , 2 ) AS " 月份 " ,
SUM ( goods_amt ) AS " 退款金额(元) "
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 ) < = ' 2025-06-30 '
GROUP BY SUBSTR ( order_time , 1 , 4 ) , SUBSTR ( order_time , 6 , 2 )
ORDER BY SUBSTR ( order_time , 1 , 4 ) , SUBSTR ( order_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 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 = ' ' ;
-- 每年底数量
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 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 < > ' ' ;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --
-- 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 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
2025-10-08 19:32:05 +08:00
- - WHERE SUBSTR ( t2 . member_register_ti me , 1 , 10 ) < = ' 2025-06-30 ' ;
2025-10-08 15:47:05 +08:00
-- 订单号关联不到积分数据
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 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 )
) 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 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 < > ' '
) 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 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 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 ;
2025-10-08 19:32:05 +08:00
-- 积分清零有大于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 ) ;
2025-10-08 15:47:05 +08:00
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --