'Querying multiple entities to identify specific rows and average time differences ORACLE
This is my first question so apologies if anything is unclear or inaccurately presented.
I have a question relating to a Helpdesk task using Oracle.
I would like to be able to query two (maybe three) entities that are connected through problemID where the Time Completed is deducted from Time Logged and then averaged using the problemID to group and order results providing the average time required for each problemType.
My problem is I can only get the database to complete one of the tasks at a time and don't know how to combine them to give me both an average time difference across multiple rows and GROUP/ORDER BY problemID.
SELECT p.problemID, AVG(CAST(TO_TIMESTAMP((p.timeCompleted),'YYYY-MM-DD HH24:MI:SS') as date)-CAST(TO_TIMESTAMP((h.timeLogged),'YYYY-MM-DD HH24:MI:SS') as date))*24*60*60 AS Average_Time_Difference
FROM Problem p, Helpdesk h
GROUP BY p.problemID
ORDER BY p.problemID;
The code above allows me to produce an average but I believe it is referencing all the dates (as I don't believe I am asking it to filter by problemID) and then providing inaccurate results:
PROBLEMID AVERAGE_TIME_DIFFERENCE
121
122 -1144515
123 492465
124 66105
What I'm really looking for is something more like this but with results that average all instances of the problemType or problemID:
SELECT pt.problemType, h.timeLogged, p.timeCompleted, TO_TIMESTAMP((p.timeCompleted),'YYYY-MM-DD HH24:MI:SS') - TO_TIMESTAMP((h.timeLogged),'YYYY-MM-DD HH24:MI:SS') AS TIME_DIFFERENCE
FROM ProblemType pt, Problem p, HelpDesk h
WHERE pt.problemTypeID = p.problemTypeID
AND p.problemID = h.problemID;
PROBLEMTYPE TIMELOGGED TIMECOMPLETED TIME_DIFFERENCE
Corrupted Drive 1/20/2022 8:58 AM 1/22/2022 10:55 AM +02 01:57:00.000000
Slow Internet 2/1/2022 11:07 AM
BSOD 1/26/2022 10:42 AM 1/27/2022 9:21 AM +00 22:39:00.000000
Password Issues 1/7/2022 11:26 AM 1/8/2022 10:38 AM +00 23:12:00.000000
Any help would be massively appreciated - thank you!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
