Hi all
I have a ms-access table with the users activity per day.
During the day, the user can be affected to more than one team, but only one team at same time.
I need to calculate the total time an user were available in that day with Team break done
Table example:
Nbr Name _Date State Team 4636 User99 02/06/2019 15:10:20 Affected 4820 4636 User99 02/06/2019 15:10:25 Withdraw 4820 4636 User99 02/06/2019 15:28:56 Affected 4820 4636 User99 02/06/2019 19:56:25 Withdraw 4820 4636 User99 02/06/2019 20:25:16 Affected 4820 4605 User1 02/06/2019 00:00:01 Affected 4823 4605 User1 02/06/2019 00:33:17 Affected 4820 4605 User1 02/06/2019 01:07:45 Withdraw 4820 4605 User1 02/06/2019 01:12:11 Affected 4820 4605 User1 02/06/2019 02:33:19 Withdraw 4820 4605 User1 02/06/2019 03:04:14 Affected 4820 4605 User1 02/06/2019 04:08:35 Withdraw 4820 4605 User1 02/06/2019 04:13:58 Affected 4820 4605 User1 02/06/2019 04:48:12 Withdraw 4820 4605 User1 02/06/2019 04:49:58 Affected 4820 4605 User1 02/06/2019 05:57:03 Withdraw 4820 4605 User1 02/06/2019 06:01:41 Affected 4820 4605 User1 02/06/2019 06:11:30 Withdraw 4820 4605 User1 02/06/2019 06:24:58 Affected 4820 4605 User1 02/06/2019 23:30:43 Affected 4823 4603 OtherUser 02/06/2019 06:01:38 Affected 4821
I supose that if for each user and for same Team, if i sum all the times for the State Affected and subtract with all the times the user the Withdraw state i will get the total, it should work
But there is a particularity. As can be seen for user User1, two consecutives Afftected state can occour, but with differents Teams. This means that the user was affected to the first Team, and
then makes a withdraw from the 1st team (no event on the table) and then was affected to the second Team
I have done the query below, but i am not sure that it works well and for sure does not works when there are two consecutives Affected states
Does anyone help me to make the ms-access query
My query:
SELECT Nbr, Name, Team, FORMAT(dateadd("s",SUM(dur),"1/1/70"),"hh:mm:ss") AS TOTAL_LogInTIME
FROM (SELECT DATEDIFF("s","1/1/70",[_Date]) * -1 AS dur, Nbr, Name, Team
FROM Eventos where State='Affected'
UNION ALL
SELECT DATEDIFF("s","1/1/70", [_Date]) AS dur, Nbr, Name, Team
FROM Eventos where State='Withdraw'
) AS t
GROUP BY Nbr, Name, Team;