总结一下,我将基于Channel / BU / Order_Store / Item_Store销售余额的每周数字营销收入分成总数的百分比来创建比率。
这个等式的困境是,如果由于给定渠道中不存在的销售/ BU / Order_Store / Item_Store / Week而存在缺失的比率,我的支出查询将乘以零,这将低估支出。如果是这种情况,我需要强制支出#Se; Sears" Item_Store由销售的BU余额。我正处在一个十字路口,可以将这个解决方案翻译成sql编码:
SELECT a.*, CDbl(a.Revenue / b.Revenue) AS Ratios
FROM
(SELECT buc.FY, buc.FM, buc.FW, buc.Rept_Chnl, buc.BU_NM,
IIf(buc.Order_Store="SEARS","Desktop","Mobile") AS Platform, buc.Item_Store, SUM(buc.Revenue) AS Revenue
FROM tbl_BUChannelReporting AS buc
WHERE buc.order_Store in ("SEARS","MG:SRS")
AND buc.Item_Store <> "MKTPL"
GROUP BY buc.FY, buc.FM, buc.FW, buc.Rept_Chnl, buc.BU_NM, IIf(buc.Order_Store="SEARS","Desktop","Mobile"), buc.Item_Store
HAVING SUM(buc.Revenue) <> 0) AS a
INNER JOIN
(SELECT buc.FY, buc.FM, buc.FW, buc.Rept_Chnl, buc.BU_NM, IIf(buc.Order_Store="SEARS","Desktop","Mobile") AS Platform, SUM(buc.Revenue) AS Revenue
FROM tbl_BUChannelReporting AS buc
WHERE buc.order_Store in ("SEARS","MG:SRS") AND buc.Item_Store <> "MKTPL"
GROUP BY buc.FY, buc.FM, buc.FW, buc.Rept_Chnl, buc.BU_NM, IIf(buc.Order_Store="SEARS","Desktop","Mobile")
HAVING SUM(buc.Revenue) <> 0) AS b
ON (a.FY = b.FY)
AND (a.FM = b.FM)
AND (a.FW = b.FW)
AND (a.Rept_Chnl = b.Rept_Chnl)
AND (a.BU_NM = b.BU_NM)
AND (a.Platform = b.Platform);
SELECT b.FY, b.FM, b.FW, b.Omniture_Channel, b.BU_NM, b.Platform, b.item_store, cdbl(b.Ratios * a.Spend) AS Spend
FROM
(SELECT s.FY, s.FM, s.FW, s.Omniture_Channel, s.BU_NM, s.Platform, sum(s.Spend) AS Spend
FROM spend_kmart AS s
GROUP BY s.FY, s.FM, s.FW, s.Omniture_Channel, s.BU_NM, s.Platform
HAVING SUM(s.Spend) <> 0) AS a
INNER JOIN
(SELECT val(i.FY) AS FY, i.FM, i.FW, i.Rept_Chnl AS Omniture_Channel, i.BU_NM, i.Platform, i.item_store, cdbl(i.Ratios) AS Ratios
FROM qry_Item_Store_Ratios_KMT_Non_MKTPL AS i
GROUP BY val(i.FY), i.FM, i.FW, i.Rept_Chnl, i.BU_NM, i.Platform, i.item_store, cdbl(i.Ratios)) AS b
ON (a.FY = b.FY)
AND (a.FM = b.FM)
AND (a.FW = b.FW)
AND (a.Omniture_Channel = b.Omniture_Channel)
AND (a.BU_NM = b.BU_NM)
AND (a.Platform = b.Platform);
提前感谢您的时间并保重!
-D
答案 0 :(得分:0)
查询无法创建不存在的数据。如果您需要显示channel / BU / Order_Store / Item_Store / Week的所有组合,即使没有数据,则需要一个包含channel / BU / Order_Store / Item_Store / Week的所有可能组合的数据集。如果每个元素都有一个表,包括Weeks,则可以通过包含它们的查询创建此数据集。此查询不会有任何JOIN子句,这会导致每个表的每个记录与其他表的每个记录相关联 - 笛卡尔积产品查询。请注意,涉及的表越多,查询越慢。然后将此查询加入销售数据表。
或者另一种方法是使用DSum()函数的52个文本框。我使用这种方法构建了一个简单的报告,显示了12个月的汇总数据。即使没有数据,我也希望每个月都能显示。