我知道关于此访问错误消息有几个问题,但它们不相关,因为我的查询不使用 DISTINCT 关键字。
我有两个类似的查询,一个包含贷方,另一个包含借方。它们按月份和类别分组。
最终,我希望在这两个表上进行完整的外部联接,以便我可以减去它们以获得每个类别中每个月的结果余额。
但是 Access 不允许完全外连接,所以我需要做一个 Right OUTER UNION LEFT OUTER WHERE Null。
我现在正在尝试在 Month 和 Category ID 字段上进行 RIGHT OUTER 连接。当我在一个字段上进行外部连接时,它按预期工作。当我在另一个字段上执行此操作时,它按预期工作,但是当我加入两个字段时,我得到“该字段太小,无法接受您尝试添加的数据量”
表格1:
由。。。生产:
SELECT [transactions by category].[categoryid] AS CategoryID,
Format([account transactions].[transaction date], "mm/yy") AS MonthYear,
Nz(SUM([transactions by category].[amount]), 0) AS
[Category Total]
FROM [transactions by category]
INNER JOIN [account transactions]
ON [account transactions].[id] =
[transactions by category].[transactionid]
WHERE [account transactions].[transaction type] <> 8
GROUP BY Format([account transactions].[transaction date], "mm/yy"),
[transactions by category].[categoryid];
表 2:
由。。。生产:
SELECT [transactions by category].[categoryid],
Format([account transactions].[transaction date], "mm/yy") AS MonthYear,
Nz(SUM([transactions by category].[amount]), 0) AS
[Category Total]
FROM [transactions by category]
INNER JOIN [account transactions]
ON [account transactions].[id] =
[transactions by category].[transactionid]
WHERE [account transactions].[transaction type] = 8
GROUP BY Format([account transactions].[transaction date], "mm/yy"),
[transactions by category].[categoryid];
给我错误的右连接:
SELECT * FROM
((SELECT [transactions by category].[categoryid],
Format([account transactions].[transaction date], "mm/yy")
AS MonthYear,
Nz(SUM([transactions by category].[amount]), 0) AS [Category Total]
FROM [transactions by category]
INNER JOIN [account transactions]
ON [account transactions].[id] =
[transactions by category].[transactionid]
WHERE [account transactions].[transaction type] = 8
GROUP BY Format([account transactions].[transaction date], "mm/yy"),
[transactions by category].[categoryid]) AS [Category Returns]
RIGHT JOIN
(SELECT [transactions by category].[categoryid] AS CategoryID,
Format([account transactions].[transaction date], "mm/yy")
AS MonthYear,
Nz(SUM([transactions by category].[amount]), 0) AS [Category Total]
FROM [transactions by category]
INNER JOIN [account transactions]
ON [account transactions].[id] =
[transactions by category].[transactionid]
WHERE [account transactions].[transaction type] <> 8
GROUP BY Format([account transactions].[transaction date], "mm/yy"),
[transactions by category].[categoryid]) AS [Category Debits]
ON [Category Returns].[categoryid] = [Category Debits].[categoryid]
AND [Category Returns].[monthyear] = [Category Debits].[monthyear] );
似乎此错误发生在文本字段中。当我使用格式时,MonthYear 字段是否会变为文本字段?即便如此,它也只有 5 个字符长。另外,当我仅在 MonthYear 列上加入时,连接有效,但只有在我同时加入两个字段时才会失败。