0

我的查询旨在将一个名为“WeightFactor”的附加字段添加到表的末尾。我的 SQL 代码如下。当我尝试运行时,我收到“缺少操作员错误”。我可以在前面的问题中看到 OVER() 是一个语法正确的语句。“WeightFactor”字段应该是 100% 的一小部分,因为我采用的是 rowprice/totalprice。当我删除 OVER 子句时,错误消失了,但结果只是在每行上显示 100%,而不是在每行上显示 100% 的正确百分比。

我被警告说 Access 不支持 OVER 所以想知道这是否属实,如果是这样,是否有任何人知道的解决方法?

SELECT  [2-C: Avg Prices by Customer Number Query].[Part Number],
    [2-C: Avg Prices by Customer Number Query].[Customer Name],
    [2-C: Avg Prices by Customer Number Query].[Customer Number],
    [2-C: Avg Prices by Customer Number Query].SumOfQuantity,
    [2-C: Avg Prices by Customer Number Query].TotalCost,
    [2-C: Avg Prices by Customer Number Query].TotalPrice,
    [2-C: Avg Prices by Customer Number Query].[Gross Margin],
    [TotalPrice] / SUM([TotalPrice]) OVER() AS WeightFactor
FROM    [2-C: Avg Prices by Customer Number Query]
4

1 回答 1

1

为什么不创建第二个查询来计算所有项目的总数?

'TotalQuery
SELECT SUM([2-C: Avg Prices by Customer Number Query].TotalPrice) AS TotalPriceOver
FROM [2-C: Avg Prices by Customer Number Query];

然后您可以在原始查询中使用这个:

'OriginalQuery
SELECT [2-C: Avg Prices by Customer Number Query].TotalPrice,
[TotalPrice]/[TotalPriceOver] AS WeightFactor
FROM [2-C: Avg Prices by Customer Number Query], TotalQuery;
于 2013-07-19T07:29:23.027 回答