0

当我在此代码中添加货币汇率时,Access 告诉我“您的查询不包括指定的表达式 [交易详情]。[货币代码] = [货币]。[货币代码] 作为聚合函数的一部分。” 这是什么意思,我该如何解决?

SELECT [Sales structure].Cluster,
       [Sales structure].Country,
       [Transaction details].[Sales company code],
       [Sales structure].[Sales company name],
       Year([Transaction details].[YYYY-MM-DD])      AS [Year],
       Month([Transaction details].[YYYY-MM-DD])     AS [Month],
       Sum([Transaction details].[Sales volume LOC]) AS Sales,
       [Transaction details].[Customer code]
FROM   Currencies
       RIGHT JOIN ([Sales structure]
                   RIGHT JOIN [Transaction details]
                     ON [Sales structure].[Sales company code] = [Transaction details].[Sales company code])
         ON Currencies.[Currency code] = [Transaction details].[Customer code]
GROUP  BY [Sales structure].Cluster,
          [Sales structure].Country,
          [Transaction details].[Sales company code],
          [Sales structure].[Sales company name],
          Year([Transaction details].[YYYY-MM-DD]),
          Month([Transaction details].[YYYY-MM-DD]),
          [Transaction details].[Customer code],
          Currencies.[CUR/EUR]
HAVING (( [Transaction details].[Currency code] = [Currencies].[Currency code] ))
ORDER  BY Year([Transaction details].[YYYY-MM-DD]),
          Month([Transaction details].[YYYY-MM-DD]); 
4

1 回答 1

3

问题是你有条款。您已经在on子句中具有连接条件,因此子句中没有必要having

SELECT [Sales structure].Cluster,
       [Sales structure].Country,
       [Transaction details].[Sales company code],
       [Sales structure].[Sales company name],
       Year([Transaction details].[YYYY-MM-DD])      AS [Year],
       Month([Transaction details].[YYYY-MM-DD])     AS [Month],
       Sum([Transaction details].[Sales volume LOC]) AS Sales,
       [Transaction details].[Customer code]
FROM   Currencies
       RIGHT JOIN ([Sales structure]
                   RIGHT JOIN [Transaction details]
                     ON [Sales structure].[Sales company code] = [Transaction details].[Sales company code])
         ON Currencies.[Currency code] = [Transaction details].[Customer code]
GROUP  BY [Sales structure].Cluster,
          [Sales structure].Country,
          [Transaction details].[Sales company code],
          [Sales structure].[Sales company name],
          Year([Transaction details].[YYYY-MM-DD]),
          Month([Transaction details].[YYYY-MM-DD]),
          [Transaction details].[Customer code],
          Currencies.[CUR/EUR]
ORDER  BY Year([Transaction details].[YYYY-MM-DD]),
          Month([Transaction details].[YYYY-MM-DD]); 

具体问题是货币代码不在group by子句中,并且它们没有被子句中的聚合函数包围having。实际上,您可能希望在selectandgroup by子句中包含货币,但这是另一个问题。

于 2013-06-03T19:30:42.063 回答