我正在尝试基于两个之间的TransactionDAte从表中获取数据。参赛作品已在表格中。但我仍然没有得到预期的结果。
Invenory Daily Facts Table
ID PartNumber Quantity PalletNo InvoiceNo TransactionDate IsAdd IsRestore
23 F005.V01.639-24V 250 1111 3/16/2016 Yes No
24 F005.V01.639-24V 120 2222 3/16/2016 Yes No
25 F005.V01.639-24V 170 1111 3333 3/16/2016 No Yes
SELECT TransactionDate,PartNumber,IsAdd, SUM(Quantity) AS Qty FROM InventoryDailyFacts
WHERE TransactionDate Between Format(#16/03/2016#,'dd/mm/yyyy') And Format(#16/03/2016#,'dd/mm/yyyy')
GROUP BY TransactionDate, PartNumber,IsAdd
ORDER BY TransactionDate desc
受影响的零行
答案 0 :(得分:1)
您必须正确格式化日期表达式,或者,如果您有值,请直接使用它:
from collections import defaultdict
word = "AZERTYUIOPAAAZ"
d = defaultdict(list)
for idx, letter in enumerate(word):
d[letter].append(idx)
print d['A'] # [0,10,11,12]
或简单地说:
SELECT TransactionDate,PartNumber,IsAdd, SUM(Quantity) AS Qty
FROM InventoryDailyFacts
WHERE TransactionDate Between #03/16/2016# And #03/16/2016#
GROUP BY TransactionDate, PartNumber,IsAdd
ORDER BY TransactionDate desc
或者,如果 TransactionDate 可能有时间部分:
SELECT TransactionDate, PartNumber, IsAdd, SUM(Quantity) AS Qty
FROM InventoryDailyFacts
WHERE TransactionDate = Date()
GROUP BY TransactionDate, PartNumber, IsAdd
ORDER BY TransactionDate desc
或者,如果 TransactionDate 是文本,则不是数据类型日期:
SELECT TransactionDate, PartNumber, IsAdd, SUM(Quantity) AS Qty
FROM InventoryDailyFacts
WHERE Fix(TransactionDate) = Date()
GROUP BY TransactionDate, PartNumber, IsAdd
ORDER BY TransactionDate desc
答案 1 :(得分:0)
这确实是一种典型的Access怪异。 虽然它是有效的SQL并且在其他RDBMS上工作,但在Access BETWEEN / AND中如果定义相同的日期则不起作用
如果您真的想要相同日期的范围,请添加时间:
SELECT TransactionDate,PartNumber,IsAdd, SUM(Quantity) AS Qty FROM InventoryDailyFacts
WHERE TransactionDate Between format(#16/03/2016 00:00:00#, 'dd/mm/yyyy hh:nn:ss') AND format(#16/03/2016 23:59:59#, 'dd/mm/yyyy hh:nn:ss')
GROUP BY TransactionDate, PartNumber,IsAdd
ORDER BY TransactionDate desc