Calculating time differences between multiple rows
936796May 11 2012 — edited May 15 2012Hi,
I have a table as below:
ID EVENT DATE
1 Start 03/05/2012 13:00:00
1 Stop 04/05/2012 15:00:00
1 Start 07/05/2012 09:00:00
1 Stop 09/05/2012 10:00:00
2 Start 06/08/2012 08:00:00
2 Stop 07/08/2012 10:00:00
I would like to calculate the total time span (in hours ideally) between 'Start' and 'Stop' for each ID, so have a rowset:
ID TimeSpan
---------------------
1 75
2 26
I would be grateful for any ideas how to solve this, ideally as a SQL solution or perhaps a function.
Many thanks!
Tom