我在 Access 2010 中有一个复杂的查询,其中:query1 是查询 WHERE field1 <> 8,而 query2 是相同的查询 WHERE field1=8。
然后我在做:
SELECT * FROM query1
INNER JOIN query2 ON query1.field2=query2.field2
WHERE query1.field3=query2.field3
这将返回 0 个结果。
但是,当我将其更改为:
SELECT * from query1
INNER JOIN query2 ON query1.field2=query2.field2
WHERE query1.field3=5 AND query2.field3=5
我确实得到了结果。这对任何人都有意义吗?它可能与被视为文本字段的字段有关吗?除了它没有引号,所以我不知道为什么会这样。
如果你以前看过这个,请告诉我。
这是完整的查询:
SELECT *
FROM (SELECT [transactions by category].[categoryid],
Month([account transactions].[transaction date]) AS TransMonth,
Year([account transactions].[transaction date]) AS TransYear,
SUM([transactions by category].[amount]) AS Amount
FROM (categories
INNER JOIN [transactions by category]
ON categories.id =
[transactions by category].categoryid)
INNER JOIN [account transactions]
ON [transactions by category].transactionid =
[account transactions].id
WHERE [account transactions].[transaction type] <> 8
GROUP BY [transactions by category].[categoryid],
Year([account transactions].[transaction date]),
Month([account transactions].[transaction date])) AS
TransactionCredits
INNER JOIN (SELECT [transactions by category].[categoryid],
Month([account transactions].[transaction date]) AS
TransMonth,
Year([account transactions].[transaction date]) AS
TransYear
,
SUM(
[transactions by category].[amount])
FROM (categories
INNER JOIN [transactions by category]
ON categories.id =
[transactions by category].categoryid)
INNER JOIN [account transactions]
ON [transactions by category].transactionid =
[account transactions].id
WHERE [account transactions].[transaction type] = 8
GROUP BY [transactions by category].[categoryid],
Year([account transactions].[transaction date]),
Month([account transactions].[transaction date]))
AS
TransactionDebits
ON TransactionCredits.[categoryid] =
TransactionDebits.[categoryid]
WHERE TransactionCredits.transyear = TransactionDebits.transyear
AND TransactionCredits.transmonth = 8
AND TransactionDebits.transmonth = 8;