Link to home
Create AccountLog in
Avatar of kalics
kalics

asked on

Calculate concurrent user sessions on Access DB

Hi, I have an Access 2016 database which has a table with user sessions (session ID's, application name, session start date/time and session end date/time). I need to find out the maximum concurrency for each application for each date.

I currently have a query as below which is taking too long (20 mins) to run but also comes out with only one day. Please can someone help with the algorithm for concurrency calculation  for Access?

SELECT TOP 1 Count(*) AS ['concurrency'], T1.Date
FROM table AS T1, table AS T2
WHERE (((T1.startTime_f) Between [T2].[startTime_f] And [T2].[endTIme_f]))
GROUP BY T1.usersessionID, T1.Date, t2.date;
Avatar of bfuchs
bfuchs
Flag of United States of America image

Would suggest an index on the startTime_f field.
If that doesn't help, perhaps you can move over this table to SQL Server Express (free edition).
Then Access is capable of executing Pass-Through queries really fast.
First, create a query that lists the timeslots used:

SELECT 
    UserLog.StartTime, 
    UserLog.EndTime
FROM 
    UserLog
GROUP BY 
    UserLog.StartTime, 
    UserLog.EndTime;

Open in new window

Save this as TimeSlots.

Then find the count of users having used any of these time slots:

SELECT 
    TimeSlots.StartTime, 
    Count(*) AS Users
FROM 
    UserLog, 
    TimeSlots
WHERE 
    (TimeSlots.StartTime Between [UserLog]![StartTime] And [UserLog]![EndTime]) 
    OR 
    (TimeSlots.EndTime Between [UserLog]![StartTime] And [UserLog]![EndTime])
GROUP BY 
    TimeSlots.StartTime;

Open in new window

Save this as TimeSlotUsers.

Finally, find the maximum count of concurrent users:

SELECT 
    DateValue([StartTime]) AS [Date], 
    Max(TimeSlotUsers.Users) AS MaxConcurrentUsers
FROM 
    TimeSlotUsers
GROUP BY DateValue([StartTime]);

Open in new window

Of course, indexes on the time fields is a must.
Avatar of kalics
kalics

ASKER

Thanks very much Gustav. This works perfectly. Only one little question though - I have user session data for multiple applications on the same table. These queries work perfectly for concurrency for one application.

When I did try to customise this for multiple applications, it comes up with the output of different applications listed, but it doesn't consider each application as unique & does not calculate concurrency for that application, but considers only the time fields and therefore provides the concurrency for the overall database.

Can you please help with any thoughts as to how to list max concurrency for each application?

Much appreciated
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of kalics

ASKER

Thanks very much Gustav. It worked like magic. Can't thank you enough.
Avatar of kalics

ASKER

Thank you so much. Incredibly helpful.
You are welcome!