我的建议是在 Access 中创建一个名为 [transactionsWithEffectiveDate] 的已保存查询。
对于[交易]
Group Date Time Receipt Amount
----- ------------------- --------------
ABC 2013-11-11 20:15:00 120
DEF 2013-11-12 06:10:00 120
ABC 2013-11-12 06:20:00 10
ABC 2013-11-12 06:49:00 400
ABC 2013-11-12 06:50:00 200
ABC 2013-11-12 06:51:00 250
和[组]
Group StartTime
----- ---------
ABC 06:50:00
DEF 05:30:00
查询
SELECT
Group,
[Date Time],
[Receipt Amount],
DateAdd("d", IIf(DateDiff("s", NewDayStart, [Date Time]) < 0, -1, 0), CDate(Int(t.[Date Time]))) AS EffectiveDate
FROM
(
SELECT
t.Group,
t.[Date Time],
t.[Receipt Amount],
CDate(Int(t.[Date Time]) + (g.StartTime - Int(g.StartTime))) AS NewDayStart
FROM
transactions t
INNER JOIN
groups g
ON g.Group = t.Group
)
返回
Group Date Time Receipt Amount EffectiveDate
----- ------------------- -------------- -------------
ABC 2013-11-11 20:15:00 120 2013-11-11
DEF 2013-11-12 06:10:00 120 2013-11-12
ABC 2013-11-12 06:20:00 10 2013-11-11
ABC 2013-11-12 06:49:00 400 2013-11-11
ABC 2013-11-12 06:50:00 200 2013-11-12
ABC 2013-11-12 06:51:00 250 2013-11-12
然后,您可以将该查询用作后续查询和报告的基础,例如,
SELECT
EffectiveDate,
Sum([Receipt Amount]) AS [SumOfReceipt Amount]
FROM transactionsWithEffectiveDate
GROUP BY EffectiveDate;