I am trying to add the total time a person is called outside their time on shift in an Access DB. I’m trying to use an SQL query to do find the high, low, and average time a person is called. My tables are as follows:
People Table
ID Last_Name First_Name Inactive Home_Phone Mobile_Phone Person_ID 1 Doe Jane 0 15558675309 13115552368 42 2 Smith John 1 12135556162 14085550001 13
Call_log Table
ID Direction To From Date_Time Result Length 1 outbound 15558675309 15556346789 12/31/2018 4:28:00 PM answered 0:03:54 2 inbound 15556346789 14085550001 12/31/2018 4:28:00 PM answered 0:04:23 3 outbound 13115552368 15556346789 12/31/2018 4:15:00 PM answered 0:01:13
Time_Entry Table
ID Person_ID Clock_In Clock_Out 1 42 01/01/2018 5:00 PM 01/01/2018 9:00 PM 2 42 01/01/2018 7:00 AM 01/01/2018 3:00 PM 3 13 01/01/2018 12:00 AM 01/01/2018 7:00 AM
I was thinking it might be something like:
Select if Direction = "Outbound", from call_log where Date_Time between Time_Entries.Clock_In and Time_Entries.Clock_Out
I’m looking for an output which contains all outbound calls to a person in the People
Table including the People.People_ID
, People.First_Name
, People.Last_Name
, Call_Log.Date_Time
, and Call_Log.length
First_Name Last_Name Date_Time Length Jane Doe 12/31/2018 4:20:00 AM 00:25:00
There is a link between the People_ID
fields in the Time_Entries
table and the People
table. I have also created a link between the Mobile_Phone
and Home_Phone
fields in the People
table and the To
and From
fields in the Call_Log
table
I after reading the comments I have changed things a little and am even further out of my swim lane. I am very new at this and I apologize if this is an elementary question. I’ve been doing research and not getting very far.
Any help would be very helpful!
Advertisement
Answer
Consider:
Query1: LogUNION
SELECT ID, Direction, To As LogPhoneNum, Date_Time, Result, Length, "To" AS Src FROM Call_Log UNION SELECT ID, Direction, [From], Date_Time, Result, Length, "From" FROM Call_Log;
Query2: PeopleUNION
SELECT ID, Last_Name, First_Name, Inactive, Home_Phone AS PeoplePhoneNum, "Home" AS Cat, Person_ID FROM People UNION SELECT ID, Last_Name, First_Name, Inactive, Mobile_Phone, "Mobile", Person_ID FROM People;
Query3:
SELECT PeopleUNION.ID, PeopleUNION.Last_Name, PeopleUNION.First_Name, PeopleUNION.Inactive, PeopleUNION.PeoplePhoneNum, PeopleUNION.Cat, PeopleUNION.Person_ID, LogUNION.Direction, LogUNION.LogPhoneNum, LogUNION.Date_Time, LogUNION.Result, LogUNION.Length, LogUNION.Src FROM LogUNION RIGHT JOIN PeopleUNION ON LogUNION.LogPhoneNum = PeopleUNION.PeoplePhoneNum;
That should get you to the output dataset shown in your question. Apply filter criteria as needed and use in subsequent queries.