DSum查询是Make Table查询时变慢

时间:2019-03-19 20:03:23

标签: ms-access ms-access-2016

我正试图确定哪些产品占销售额的80%,因此需要一种方法来获得我的数据的总和以及总和。如果只是选择查询,则查询运行相对较快,但是一旦将其更改为“生成表”查询,它就会陷入困境。如果检查一年的销售额,我会得到大约26,000个不同的产品代码。

这是查询的SQL代码:

SELECT
    tblRaw.ID,
    tblRaw.PRODUCT,
    tblRaw.PRODUCT_DESC,
    tblRaw.CAT_1,
    tblRaw.CATEGORY_DESC,
    tblRaw.QTY_Sold,
    tblRaw.Sales,
    tblRaw.Cost,
    IIf([Sales]=0,0,([Sales]-[Cost])/[Sales]) AS [GM%],
    Format(DSum("[Sales]","[tblRaw]","[ID]<=" & [ID]),"$#,##0") AS RunTot,
    Format(DSum("[Sales]","[tblRaw]"),"$#,##0") AS TotSum,
    ([RunTot]/[TotSum]) AS CummPer,
    IIf([CummPer]<=0.8,"A",IIf([CummPer]<=0.95,"B","C")) AS Class,
    tblOH_Company.OH_QTY AS QTY_OH,
    tblOH_Company.Value AS Value_OH
FROM tblRaw LEFT JOIN tblOH_Company ON tblRaw.PRODUCT = tblOH_Company.Product
ORDER BY tblRaw.Sales DESC;

注意:如果删除联接表(tblOH_Company),则看不到任何改善。

任何建议将不胜感激。

0 个答案:

没有答案