我有以下表格 -
**TimeLogs**
ID
UserID
JobID
TimeTaken
**Jobs**
ID
EstimatedTime
ActualTime
**ClockInLogs**
ID
UserID
ClockDateTimeIn
ClockDateTimeOut
以下查询生成重复记录 -
SELECT tl.JobID, TimeTaken as 'HoursSold',
DATEDIFF(minute, ClockDateTimeIn, ClockDateTimeOut) / 60 as Hours_Difference,
DATEDIFF(second, ClockDateTimeIn, ClockDateTimeOut) / 60 as Minutes_Difference
from TimeLogs tl
INNER JOIN Jobs j on tl.JobID = j.ID
LEFT JOIN ClockInLogs cil on tl.UserID = cil.UserID
where tl.UserID = 10000 and
ClockDateTimeIn BETWEEN DATEADD(wk, DATEDIFF(wk,0,'11/08/2013'), 0) AND
DATEADD(wk, DATEDIFF(wk,0,'11/08/2013'), 6)
group by tl.ID, tl.JobID, j.TotalEstimatedCharge, tl.TimeTaken, cil.ClockDateTimeIn, cil.ClockDateTimeOut
我想做的是返回 HoursWorked、Hours_Difference 和 Minutes_Difference 的总和——没有重复。我无法弄清楚重复的来源。有任何想法吗?
谢谢