通过CTE SQL查询进行数据分析,了解乳制品运输业务的趋势。什么样的包装,最常搬动的物品,最繁忙的区域

发布于 2025-01-11 15:42:18 字数 2500 浏览 5 评论 0原文

我能够使用此查询获取所有记录,并希望使用 CTE 将其分解以进行简单的 DA,以了解我们每月使用的包装量,哪些 SKU 每月移动最多, 以及按地点划分的数量。如果我在 2021 年执行此操作,我会因超过 1500 万条记录而超时 30 分钟。我想学习如何使用 SQL

SELECT
SKU,
,boxsize
,month
,CASE WHEN aisle IN ('700','781') THEN 'Dairy' ELSE 'FrozenDairy' END AS Location

FROM production_table 

JOIN date_table t2
    ON to_date(create_tstamp_local) = t2.date
    
JOIN aisle_info t3
    ON sku= t3.sku
    
JOIN orders_table t4
  ON delivery_number =t4.delivery_num
  
WHERE order_status = 'shipped'
AND filling_rsc = 'IL01'
AND t3.aisle_num IN ('780','781','682','683','684','685','686','687','688','689','690','692')
AND t2.year = 2021
AND t4.shipped = 'F'

结果回答这些问题:

SKUboxsizeMonthLocation
104567812x12x12155
10456786x6x6253
579667812x12x12155
104567812x12x12155

预期表结果:

表 1:包装每月按 SKU 分析不同盒子尺寸计数

SKU盒子尺寸BoxSizeCount每月位置
104567812x12x121,000,000155
10456786x6x61,000,000155
104567812x12x12200,000255
10456786x6x6200,000255
579667812x12x12100,000353
104567812x12x12100,000355

表 2:按每月 SKU 划分的不同盒子尺寸计数的 SKU 分析

SKUSKUCount位置
10456781,500,000155
90456721,000,000155
1032618220,000155
1045673245,000155
5796678175,000253
1031045678100,039253

我可以导出这两个表以用于第三次位置分析。

I am able to grab all records with this Query and want to break it down using CTE for simple DA in understanding the volume of packaging we use per month, which SKUs move most per month,
and volume by location. If I do this for the year 2021 I get timed out at 30 minutes with over 15 million records. I want to be learn how to answer these questions using SQL

SELECT
SKU,
,boxsize
,month
,CASE WHEN aisle IN ('700','781') THEN 'Dairy' ELSE 'FrozenDairy' END AS Location

FROM production_table 

JOIN date_table t2
    ON to_date(create_tstamp_local) = t2.date
    
JOIN aisle_info t3
    ON sku= t3.sku
    
JOIN orders_table t4
  ON delivery_number =t4.delivery_num
  
WHERE order_status = 'shipped'
AND filling_rsc = 'IL01'
AND t3.aisle_num IN ('780','781','682','683','684','685','686','687','688','689','690','692')
AND t2.year = 2021
AND t4.shipped = 'F'

Result:

SKUboxsizemonthLocation
104567812x12x12155
10456786x6x6253
579667812x12x12155
104567812x12x12155

Expected table results:

TABLE 1: Packaging analysis of distinct box size counts by SKU per month

SKUboxsizeBoxSizeCountmonthLocation
104567812x12x121,000,000155
10456786x6x61,000,000155
104567812x12x12200,000255
10456786x6x6200,000255
579667812x12x12100,000353
104567812x12x12100,000355

TABLE 2: SKU analysis of distinct box size counts by SKU per month

SKUSKUCountmonthLocation
10456781,500,000155
90456721,000,000155
1032618220,000155
1045673245,000155
5796678175,000253
1031045678100,039253

I can export these two tables to use for the third Location analysis.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

阳光下的泡沫是彩色的 2025-01-18 15:42:18
SKU,
,boxsize
,month
,CASE WHEN aisle IN ('700','781') THEN 'Dairy' ELSE 'FrozenDairy' END AS Location
**,COUNT(1) AS record_count**

FROM production_table 

JOIN date_table t2
    ON to_date(create_tstamp_local) = t2.date
    
JOIN aisle_info t3
    ON sku= t3.sku
    
JOIN orders_table t4
  ON delivery_number =t4.delivery_num
  
WHERE order_status = 'shipped'
AND filling_rsc = 'IL01'
AND t3.aisle_num IN ('780','781','682','683','684','685','686','687','688','689','690','692')
AND t2.year = 2021
AND t4.shipped = 'F'

**GROUP BY 1,2,3,4,5,6,7**`
SKU,
,boxsize
,month
,CASE WHEN aisle IN ('700','781') THEN 'Dairy' ELSE 'FrozenDairy' END AS Location
**,COUNT(1) AS record_count**

FROM production_table 

JOIN date_table t2
    ON to_date(create_tstamp_local) = t2.date
    
JOIN aisle_info t3
    ON sku= t3.sku
    
JOIN orders_table t4
  ON delivery_number =t4.delivery_num
  
WHERE order_status = 'shipped'
AND filling_rsc = 'IL01'
AND t3.aisle_num IN ('780','781','682','683','684','685','686','687','688','689','690','692')
AND t2.year = 2021
AND t4.shipped = 'F'

**GROUP BY 1,2,3,4,5,6,7**`
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文