这是在 Excel 中进行的一个非常简单的计算,但我很难理解如何在 Access 中使用不同记录中的表中的 2 个字段来执行此操作。我有一个应用程序需要找到操作 STOPTime 和下一个 STARTTime 之间的区别。任何帮助将不胜感激。我是 VBA 新手。
问问题
175 次
2 回答
1
Sub samPle()
Dim startTime As Date
Dim endTime As Date
startTime = Time
'''Your Code
endTime = Time
Debug.Print DateDiff("n", startTime, endTime) ' difference in minutes
End Sub
于 2013-02-21T19:03:26.710 回答
0
根据您的数据,有多种方法可以解决问题,这使得发布有关 SQL 问题的数据非常重要。例如:
桌子:
ID EventTime EventType
1 17/02/2013 08:52:00 start
2 17/02/2013 09:52:00 stop
3 17/02/2013 11:52:00 start
4 17/02/2013 15:52:00 stop
SQL:
SELECT a.id,
a.eventtime AS Start,
a.eventtype,
(SELECT TOP 1 eventtime
FROM times b
WHERE eventtype = "stop"
AND eventtime > a.eventtime
ORDER BY eventtime,
id) AS Stop,
Datediff("n", [start], [stop]) AS RunTime
FROM times AS a
WHERE (( ( a.eventtype ) = "start" ))
ORDER BY a.eventtime;
结果:
ID Start EventType Stop RunTime
1 17/02/2013 08:52:00 start 17/02/2013 09:52:00 60
3 17/02/2013 11:52:00 start 17/02/2013 15:52:00 240
重新评论
SELECT a.id,
a.eventtime AS Start,
a.eventtype,
(SELECT TOP 1 eventtime
FROM times b
WHERE eventtype = "stop"
AND eventtime > a.eventtime
ORDER BY eventtime,
id) AS Stop,
Datediff("n", [start], [stop]) AS RunTime,
(SELECT TOP 1 eventtime
FROM times b
WHERE eventtype = "start"
AND eventtime > a.eventtime
ORDER BY eventtime,
id) AS NextStart,
Datediff("n", [start], [nextstart]) AS StartDiff,
Datediff("n", [stop], [nextstart]) AS DownTime
FROM times AS a
WHERE (( ( a.eventtype ) = "start" ))
ORDER BY a.eventtime;
于 2013-02-21T21:00:05.073 回答