我有一个表格,其中包含工人ID“tblWORKERS”和一个查询,其中包含每个工人所做的所有交易“QryTRANSACTIONS”。
QryTRANSACTIONS:
WorkerID|TransactionDate|AMOUNT
A | 01/01/2017 | $500
B | 01/01/2017 | $600
A | 01/16/2017 | $300
B | 01/16/2017 | $700
A | 02/01/2017 | $1,200
B | 02/01/2017 | $1,300
A | 02/16/2017 | $900
B | 02/16/2017 | $2,000
A | 03/01/2017 | $5,000
B | 03/01/2017 | $8,000
所以现在我需要2月份发生的WorkerID A的交易总和 所以我这样做了:
ExtrasSimples: DSum("AMOUNT","QryTRANSACTIONS","WorkerID = '" &
[tblWORKERS]![WorkerID] & "' AND
TransactionDate >= #" & DateSerial(2017,2,1) & "# AND
TransactionDate <= #" & DateSerial(2017,2,28) & "#")
正确的答案是:2,100美元(第5行和第7行)但是Access给了我:2,500美元(第3,5和7行)..为什么?
答案 0 :(得分:0)
不确定为什么会发生这种情况,但如果你想要整个月,这些日子就无关紧要了。尝试:
ExtrasSimples: DSum("AMOUNT","QryTRANSACTIONS","WorkerID = '" &
[tblWORKERS]![WorkerID] & "' AND
Format(TransactionDate,'yyyymm') = '" & Format([TransactionDate], "yyyymm") & "'")