您的查询不包含指定的表达式。它是什么意思,我该如何解决?

时间:2013-06-03 19:00:05

标签: sql ms-access

当我在此代码中添加货币汇率时,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]); 

1 个答案:

答案 0 :(得分: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子句中的聚合函数包围。实际上,您可能希望在selectgroup by子句中加入货币,但这是另一个问题。