调整 格式
This commit is contained in:
+1
-42
@@ -89,41 +89,6 @@ shop_stock_latest AS (
|
||||
t."店铺主键"
|
||||
),
|
||||
|
||||
sales_summary AS (
|
||||
SELECT
|
||||
fs."统一规格编码",
|
||||
fs."店铺主键",
|
||||
SUM(
|
||||
CASE
|
||||
WHEN fs."发货时间" >= date_trunc('month', now())
|
||||
AND fs."发货时间" < date_trunc('month', now()) + INTERVAL '1 month'
|
||||
THEN fs."销售数量"
|
||||
ELSE 0
|
||||
END
|
||||
) AS "本月销售数量",
|
||||
SUM(
|
||||
CASE
|
||||
WHEN fs."发货时间" >= date_trunc('month', now()) - INTERVAL '1 month'
|
||||
AND fs."发货时间" < date_trunc('month', now())
|
||||
THEN fs."销售数量"
|
||||
ELSE 0
|
||||
END
|
||||
) AS "上月销售数量",
|
||||
SUM(
|
||||
CASE
|
||||
WHEN fs."发货时间" >= date_trunc('month', now()) - INTERVAL '2 month'
|
||||
AND fs."发货时间" < date_trunc('month', now()) - INTERVAL '1 month'
|
||||
THEN fs."销售数量"
|
||||
ELSE 0
|
||||
END
|
||||
) AS "上上月销售数量"
|
||||
FROM analytics_layer.fact_sales fs
|
||||
WHERE NULLIF(TRIM(fs."统一规格编码"), '') IS NOT NULL
|
||||
AND fs."发货时间" >= date_trunc('month', now()) - INTERVAL '2 month'
|
||||
AND fs."发货时间" < date_trunc('month', now()) + INTERVAL '1 month'
|
||||
GROUP BY fs."统一规格编码", fs."店铺主键"
|
||||
),
|
||||
|
||||
product_dim AS (
|
||||
SELECT DISTINCT ON ("统一规格编码")
|
||||
"统一规格编码",
|
||||
@@ -148,18 +113,12 @@ SELECT
|
||||
pd."零售价",
|
||||
ds."店铺名称",
|
||||
COALESCE(sl."可发库存", 0) AS "店铺挂单量",
|
||||
COALESCE(inv."总库存", 0) AS "总库存",
|
||||
COALESCE(ss."本月销售数量", 0) AS "本月销售数量",
|
||||
COALESCE(ss."上月销售数量", 0) AS "上月销售数量",
|
||||
COALESCE(ss."上上月销售数量", 0) AS "上上月销售数量"
|
||||
COALESCE(inv."总库存", 0) AS "总库存"
|
||||
FROM shop_stock_latest sl
|
||||
LEFT JOIN inventory_summary inv
|
||||
ON sl."统一规格编码" = inv."统一规格编码"
|
||||
LEFT JOIN analytics_layer.dim_shop ds
|
||||
ON sl."店铺主键" = ds."店铺主键"
|
||||
LEFT JOIN sales_summary ss
|
||||
ON sl."统一规格编码" = ss."统一规格编码"
|
||||
AND sl."店铺主键" = ss."店铺主键"
|
||||
LEFT JOIN product_dim pd
|
||||
ON sl."统一规格编码" = pd."统一规格编码"
|
||||
WHERE pd."品牌名称" = {brand_filter}
|
||||
|
||||
Reference in New Issue
Block a user