I\'m stuck. I\'ve looked for an answer, but can\'t seem to find subtracting time in the same table from two different rows of the same table that fits. I\'m having a difficu
I have solved this for similar problems and it need not be that the rows even be sorted:
select t1.EmpID, t1.TimeIn, t1.TimeOut,
datediff(minute, max(t2.TimeOut), t1.TimeIn) as minutes
from timesheet t1 left join timesheet t2 on t1.EmpID = t2.EmpID
and t2.TimeOut < t1.TimeIn
group by t1.EmpID, t1.TimeIn, t1.TimeOut
Let me know if this works.
Here is a sql fiddle: http://sqlfiddle.com/#!3/89a43/1