使用每月数据MS-Access 2010加入每日数据

时间:2016-11-22 22:36:17

标签: sql ms-access

我无法将每日数据(已汇总到月度数据)与月度数据相关联。我在Excel中有一个财务数据库,有两个表:

  1. 支出 - 购买时所有带有类别和日期(日/月/年)的购买

  2. 收入 - 按日期(月/年)的月收入

  3. 我有一个查询,它将每日支出汇总并按月分组:

    SELECT Format(Outlays.period,"mmm-yy") AS Period, Sum(Outlays.Value) AS [Living Cost]
    FROM Outlays
    GROUP BY Format(Outlays.period,"mmm-yy"), Outlays.[Living Cost]
    HAVING (((Outlays.[Living Cost])=True));
    

    我遇到麻烦的地方是将收入数据加入此查询:

    SELECT Format(Outlays.period,"mmm-yy") AS Period, Sum(Outlays.Value) AS [Living Cost]
    FROM Outlays
    JOIN Income ON Outlays.period = Income.Period
    GROUP BY Format(Outlays.period,"mmm-yy"), Outlays.[Living Cost]
    HAVING (((Outlays.[Living Cost])=True));
    

    此查询返回“FROM子句中的语法错误”。

    非常感谢有关正确语法的任何想法。

1 个答案:

答案 0 :(得分:1)

在MS Access SQL中,您需要显式声明JOIN的类型,而不是将其一般地保留为JOIN。而在其他RDMS中,JOIN默认为INNER JOIN,在MS Access中您必须声明它。

FROM Outlays INNER JOIN Income ON Outlays.period = Income.Period

对于多个连接,必须将表/查询配对括在括号中:

FROM ((Outlays 
INNER JOIN Income ON Outlays.period = Income.Period)
INNER JOIN OtherTable ON Outlays.id = OtherTable.id)
INNER JOIN AnotherTable ON Outlays.id = AnotherTable.id