Where clause Access 2010 WHERE子句未按预期工作
我在Access 2010中有一个复杂的查询,其中: 查询1是一个查询,其中字段1 8 和 查询2与字段1=8的查询相同 然后我在做:Where clause Access 2010 WHERE子句未按预期工作,where-clause,ms-access-2010,Where Clause,Ms Access 2010,我在Access 2010中有一个复杂的查询,其中: 查询1是一个查询,其中字段1 8 和 查询2与字段1=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.fiel
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;
好几个月来,我一直在用头撞墙。我终于找到了解决办法,但我不完全明白为什么会这样 而不是仅仅说
SELECT *
FROM query1
INNER JOIN query2 ON query1.field2=query2.field2
WHERE query1.field3=query2.field3"
我把WHERE子句改为
VAL(query1.field3)=VAL(query2.field3)
这两个字段最初都是整数ID列,但显然其中一个字段在某个查询中的某个地方变成了某种文本字段
我仍然有兴趣听一个解释这是如何工作的
感谢Val在您的示例中将文本字段转换为数字,这意味着您没有数据类型不匹配。你想解释什么?顺便说一句,最好避免使用*来选择字段。