目的
制定销售报告,输出产品目录以展示新产品/现有产品。报告详情包括:
CUSTOMER ID
)ITEM ID
& CUSTOMER ID
)ITEM ID
& CUSTOMER ID
)首先,一点背景
最初,我制作的报告突出显示了特定商品(COMPANY ID
)的公司(PURCHASE ORDER DATE
)历史采购订单(最大值(ITEM ID
))。但是,这很快就失败了,因为 new 产品也是目录的一部分(没有PURCHASE ORDER DATE
的历史记录)。更糟糕的是,我们公司预测需要物品(DEMAND FORECAST
),即使产品是全新的(为什么会这样,我也不知道)。
因此,CUSTOMER
和ITEM ID
无法直接相关(因为有时客户会展示新产品)。
更糟糕的是,CUSTOMER
可能有多个CUSTOMER NAMES
(例如" Home Depot"," HOME DEPOT ONLINE"等。 )
APPROACH
Customer IDs
,Customer Names
(已完成)Item ID
及其Inventory
(已完成)Purchase orders
)表(最新采购订单),包括Customer IDs
和Item IDs
(已完成)Demand Forecasts
和Customer ID
(已完成)Item ID
表格
Customer Name
与Item ID
相关联,具体取决于我们是否要展示某些新产品/现有产品(不完整) ITEM ID
和 LIKE CUSTOMER NAME
(因为1个客户可以有多个名称变体)。 注意:重申一下,我必须采取步骤#3和#4的原因是公司可以有采购订单,但没有预测;或预测,但没有每个项目的先前采购订单。因此,需要步骤#5来巩固Company ID
和Item
之间的链接,并且步骤#6增加了复杂性,因为我们的数据库搞砸了......
CODE
SELECT
[Active Catalog].[CUSTOMER NAME],
[Table - Item and Company Forecasted Sales].[COMPANY ID],
[Table - Item and Company Forecasted Sales].ITEM,
[Table - Item and Company Forecasted Sales].STYLE,
[Table - Item and Company Forecasted Sales].DESCRIPTION,
[Table - Item and Company Historic Sales].PRICE,
[Table - Item and Company Forecasted Sales].[ON-HAND QTY],
[Table - Item and Company Forecasted Sales].[FORECAST QTY],
[Table - Item and Company Historic Sales].[LATEST PO DATE]
INTO [Table - Summary]
FROM ([Active Catalog]
INNER JOIN [Table - Item and Company Forecasted Sales]
ON ([Active Catalog].STYLE = [Table - Item and Company Forecasted Sales].STYLE)
AND ([Active Catalog].[CUSTOMER NAME] LIKE '%' + [Table - Item and Company Forecasted Sales].[CUSTOMER NAME] + '%'))
INNER JOIN [Table - Item and Company Historic Sales]
ON ([Active Catalog].STYLE = [Table - Item and Company Historic Sales].STYLE)
AND ([Active Catalog].[CUSTOMER NAME] LIKE '%' + [Table - Item and Company Historic Sales].[CUSTOMER NAME] +'%')
GROUP BY
[Active Catalog].[CUSTOMER NAME],
[Table - Item and Company Forecasted Sales].[COMPANY ID],
[Table - Item and Company Forecasted Sales].ITEM,
[Table - Item and Company Forecasted Sales].STYLE,
[Table - Item and Company Forecasted Sales].DESCRIPTION,
[Table - Item and Company Historic Sales].PRICE,
[Table - Item and Company Forecasted Sales].[ON-HAND QTY],
[Table - Item and Company Forecasted Sales].[FORECAST QTY],
[Table - Item and Company Historic Sales].[LATEST PO DATE];
问题
ITEM ID
AND 的表格CUSTOMER NAME
的相对可能性,因为如上所述,1 { {1}}有多个但相似CUSTOMER ID
(例如HOMEDEPOT,HOMEDEPOT ONLINE)。但是,我的代码似乎不正确。请参阅上面的代码中的CUSTOMER NAMES
。