SQL Server 2008: Getting duration between user sessions

Posted by Nai on Stack Overflow See other posts from Stack Overflow or by Nai
Published on 2010-05-12T18:23:53Z Indexed on 2010/05/12 18:34 UTC
Read the original article Hit count: 274

Filed under:
|
|
|

I have this table

UserID   SessionID   SessionStart   SessionEnd
-----------------------------------------------
1        abc1        2010-1-1       2010-1-2
5        def3        2010-1-5       2010-1-9
1        llk0        2010-1-10      2010-1-11
5        spo8        2010-1-13      2010-1-15
1        pie7        2010-1-16      2010-1-29

I would like to be able to find the days between the end of one session to the start of the next session for each particular user.

So I am looking to get something like

UserID   DaysBetweenSessions
-----------------------------
1        8
1        5
5        4

Thanks!

© Stack Overflow or respective owner

Related posts about sql

Related posts about tsql