468,720 Members | 1,715 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,720 developers. It's quick & easy.

How to find maximum concurrent users and sessions by Login and Logout Time?

I am trying to figure out the solution using co-related sub-query but somehow getting stuck with 'odd-dates' instead of # of max(concurrent users) and sessions for particular applications. Any help would be really appreciable.

Below is the reference query and output snapshot:-

SELECT ExtensionID, ClientCode, LoginTime, LogoutTime
FROM ( SELECT ExtensionID, ClientCode, AuditDate as LoginTime, Change, isnull(LEAD(AuditDate) OVER (PARTITION BY ExtensionID ORDER BY AuditDate), GETDATE()) as LogoutTime
FROM (SELECT ExtensionID, ClientCode, AuditDate, case when AssignedEmployeeID is not null then 1 when AssignedEmployeeID is null then -1 else 0 end as change
from Focus.Mallaka.TollExtensions as ext with (nolock)
WHERE AuditDate between DATEADD(Day,-7,GETDATE()) and GETDATE()
) as subQ
) as LeadSubQuery
WHERE Change = 1
order by ExtensionID, LoginTime;
Attached Images
File Type: png SQLOutput_050618.PNG (9.8 KB, 49 views)
Jun 6 '18 #1
0 1933

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Dave Kissoondoyal | last post: by
4 posts views Thread by Ollie | last post: by
6 posts views Thread by Bill Manring | last post: by
5 posts views Thread by samatair | last post: by
9 posts views Thread by bryonone | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.