I have user session ids and the timestamp of the session ids where some event occurs. I want to calculate the time between the first event and the last event. Please see the example below:
session_id timestamp
sess1 2018-11-05 14:28:25.260
sess2 2018-11-04 12:14:59.576
sess2 2018-11-04 11:55:00.584
sess2 2018-11-04 12:16:44.702
sess3 2018-11-04 12:04:37.419
I want to calculate the difference between the first and last timestamp of sess2 and likewise all other session_ids like this:
session_id timeSpent
sess1 1
sess2 125 (for example)
sess3 1
How to calculate this?