所以我需要从我的一个查询中加上时间。我有志愿者,他们有startTime和EndTime。然后我使用此代码通过查询计算它:
SELECT v.Name, Format(v.StartTime - v.EndTime, "hh:nn:ss") AS Time_Diffrence,
FROM VOLUNTEERS AS o, VOL_TASKS AS v, TASKS AS t
WHERE v.Taskcode = t.Taskcode
AND v.Name = o.Name
ORDER BY 1;
因此,为每个志愿者提供Time_Diffrence(注意我在代码中拼写错误)。但是现在我需要在另一个查询中总结Time_Difference的总数。我该怎么做呢?
这是我到目前为止的代码,但它甚至没有运行:/
SELECT v.Name, Format(v.StartTime - v.EndTime, "hh:nn:ss") AS Time_Diffrence,
Time_Diffrence = SUM(DATEDIFF(MINUTE, '0:00:00', WrkHrs))
FROM VOLUNTEERS AS o, VOL_TASKS AS v, TASKS AS t
WHERE v.Taskcode = t.Taskcode
AND v.Name = o.Name
GROUP BY v.Name
ORDER BY 1 Asc;
有什么想法吗?
答案 0 :(得分:0)
SELECT v.Name, SUM(DATEDIFF(SECOND, v.StartTime, v.EndTime)) AS TimeDiffInSecs
FROM Volunteers AS v
INNER JOIN Vol_Tasks AS vt
ON v.Name = vt.Name
INNER JOIN Tasks AS t
ON v.TaskCode = t.TaskCode
GROUP BY v.Name
这应该总结每个用户的所有记录,并给出总工作秒数。 (我没有做几分钟,因为你可能会因为四舍五入而浪费时间)