Access 2007,OVER子句变通方法 - 缺少运算符错误

时间:2013-07-18 19:27:12

标签: ms-access over-clause

我的查询旨在将一个名为“WeightFactor”的附加字段添加到表的末尾。我的SQL代码如下。当我尝试运行时,我收到“缺少操作员错误”。我可以在之前的问题中看到OVER()是一个语法正确的语句。自从我采用rowprice / totalprice以来,“WeightFactor”字段应该是100%的一小部分。当我删除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]

1 个答案:

答案 0 :(得分: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;