I have a table with the following data:
userID tStamp status
------ ------------------- ------
Jason 2017-10-18 03:20:00 idle
Brown 2017-10-18 03:20:28 idle
Brown 2017-10-18 03:25:28 idle
Brown 2017-10-18 04:00:28 active
Brown 2017-10-18 04:10:28 active
Brown 2017-10-18 04:35:28 idle
Brown 2017-10-18 04:45:28 idle
I want to extract the consecutive rows with the same status. For example, I want to see the time spent by a user in the 'idle' status, followed by 'active' status, followed by 'idle' status, and so on.
How do I do this in a single SQL query?
My desired output is the following:
userID staus Duration_in_this_status (min)
------ ------------------- ------
Jason idle ---
Brown idle 5
Brown active 10
Brown idle 10
@variables
as you walk through the table inORDER BY ...
.