I need to find the number of hours each user is logged into an application per week. The table structure is as follows:
[ID]
[UserID]
[Time] (datetime field)
[EventType] ("login" or "logout")
There can be many logins/logouts per day. Since it would probably be significantly easier to get the first login and last logout of the day, that is also acceptable (although less accurate).
Any suggestions where to start? I'll probably have to do some partitioning, right?
The table logs the launch of a desktop application. The application will time out on its own without activity. Launching another instance of the application will log out your active session and start a new one, so I don't think there could be an overlap. I do not have control over the data types as they are part of the application. EventType is a string.
Best Answer
There's probably a more elegant solution but using your criteria from your comment to @Erik that the logout will be recorded this should get you what you need, or very close: