I am new to SQL and I was wondering if the following is even possible to achieve.
Using SQL Server 2012 I would like to find the total time a given entity has spent in one location in minutes. There are multiple entries for each entity as they may have gone in and out of a given location many times during the day, I just want to find the total time spent in minutes for all the time spent for a given location.
The table has two datetime
columns that display Starttime
and Endtime
, along with location ID and Entity ID.
I have managed to find a way to work out the time difference between Starttime
and Endtime
for one event, but I want to sum for all those events in the location to be displayed as total time.
Please let me know if I need to give any more information
What you need to do is to calculate the date difference between the locations where the entity had spent time, as below
Result Values
Use the below query to get the desired result
Result values would be