在三个访问表之间进行查询不会返回值

时间:2018-08-29 19:56:11

标签: sql ms-access ms-access-2010

enter image description here enter image description here我有三个Access表。我试图使查询取决于日期,但查询不返回任何值。

SELECT Sum(income2.mony) AS SumOfmony, Sum(outcome.mony) AS SumOfmony1, Sum(PT.PT_Paid) AS SumOfPT_Paid, Sum(PT.PT_Remain) AS SumOfPT_Remain, PT.PT_Date
FROM (PT INNER JOIN income2 ON PT.PT_Date = income2.dat) INNER JOIN outcome ON PT.PT_Date = outcome.[dat&time]
GROUP BY PT.PT_Date;

enter image description here

1 个答案:

答案 0 :(得分:0)

好像您要子查询,而不是联接。 INNER JOIN不返回不匹配结果的记录。

然后,还有另一个问题:日期可以存储几分之一秒。比较日期是否相等会导致Access出现问题(示例,请参见this

尝试使用以下子查询查询外部表:

SELECT Sum(income2.mony) FROM income2 WHERE DateDiff("s",PT.PT_Date, income2.dat) = 0
SELECT Sum(outcome.mony) FROM outcome WHERE DateDiff("s",PT.PT_Date, outcome.[dat&time]) = 0

已实施:

SELECT
    (SELECT Sum(income2.mony) FROM income2 WHERE DateDiff("s",PT.PT_Date, income2.dat) = 0) As SumOfmony,
    (SELECT Sum(outcome.mony) FROM outcome WHERE DateDiff("s",PT.PT_Date, outcome.[dat&time]) = 0) AS SumOfmony1,
    Sum(PT.PT_Paid) AS SumOfPT_Paid, Sum(PT.PT_Remain) AS SumOfPT_Remain, PT.PT_Dat
FROM PT
GROUP BY PT.PT_Date;