Discussions
Categories
- 196.7K All Categories
- 2.2K Data
- 235 Big Data Appliance
- 1.9K Data Science
- 449.8K Databases
- 221.5K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 549 MySQL Community Space
- 477 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3K ORDS, SODA & JSON in the Database
- 532 SQLcl
- 4K SQL Developer Data Modeler
- 186.8K SQL & PL/SQL
- 21.2K SQL Developer
- 295.3K Development
- 17 Developer Projects
- 138 Programming Languages
- 292K Development Tools
- 104 DevOps
- 3.1K QA/Testing
- 645.9K Java
- 27 Java Learning Subscription
- 37K Database Connectivity
- 153 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.1K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 17 Java Essentials
- 158 Java 8 Questions
- 85.9K Java Programming
- 79 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.2K Java SE
- 13.8K Java Security
- 203 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 390 LiveLabs
- 37 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.6K Other Languages
- 2.3K Chinese
- 170 Deutsche Oracle Community
- 1K Español
- 1.9K Japanese
- 230 Portuguese
How to Calculate Average Daily Time from Start_Time and End_Time fields

I am using ORACLE 11G on Red Hat Linux, I am trying to calculated the average Daily time from multiple transactions for each day. The followign is the querry which shows the time difference between the start_ time and end_time fields.
select TRIP_LOAD_STARTED AS START_TIME,TRIP_LOAD_ENDED AS END_TIME,
ceil(( TRIP_LOAD_EDDT - TRIP_LOAD_STDT) * 1440) " Time Difference Bw Start and End"
from GATE2GATE_ACTIVITY_VW
Where TRIP_LOAD_STARTED >= '01/FEB/14'
AND TRIP_LOAD_ENDED < '03/FEB/14'
ORDER BY TRIP_LOAD_STARTED;
The above querry gives me the output as follows:
Start_Time End_Time Time Diff bw Start and End
01/FEB/14 01/FEB/14 18
01/FEB/14 01/FEB/14 18
01/FEB/14 01/FEB/14 18
01/FEB/14 01/FEB/14 18
01/FEB/14 01/FEB/14 18
01/FEB/14 01/FEB/14 18
01/FEB/14 01/FEB/14 12
02/FEB/14 02/FEB/14 29
02/FEB/14 02/FEB/14 29
02/FEB/14 02/FEB/14 29
02/FEB/14 02/FEB/14 29
02/FEB/14 02/FEB/14 19
02/FEB/14 02/FEB/14 19
02/FEB/14 02/FEB/14 19
It shows two dates for which I want to get the average time in minutes for each date group by the start time.
I am using the following querry which probably is giving me the average of the two days mentioned in where clause
select floor(avg(( TRIP_LOAD_STARTED - TRIP_LOAD_ENDED) * 1440)) " Average time Minutes "
from gate2gate_activity_vw
Where TRIP_LOAD_STDT >= '01/FEB/14'
AND TRIP_LOAD_STDT < '03/FEB/14';
Average Time in Minutes
29
Can anyone help me to calculated Daily Average time between Start and EndTime.
Kind regards,
mhamidch
Best Answer
-
Is this what you want:
SELECT trunc(TRIP_LOAD_STARTED),trunc(TRIP_LOAD_ENDED),
floor(avg(ceil(( TRIP_LOAD_ENDED - TRIP_LOAD_STARTED) * 1440))) Diff
FROM GATE2GATE_ACTIVITY_VW
WHERE TRIP_LOAD_STARTED >= to_date('01/FEB/2014','dd/MON-YYYY')
AND TRIP_LOAD_ENDED < to_date('03/FEB/2014','dd/MON-YYYY')
GROUP BY trunc(TRIP_LOAD_STARTED), trunc(TRIP_LOAD_ENDED)
Always post the sample create table and insert statements to verify the results and use to_date function with date format.
Message was edited by: Moazzam
Answers
-
hi,
Please provide the time as well along with the dates to calculate the exact time,
DD/MM/YYYY hh24:mm:si format
Thank you.
-
Is this what you want:
SELECT trunc(TRIP_LOAD_STARTED),trunc(TRIP_LOAD_ENDED),
floor(avg(ceil(( TRIP_LOAD_ENDED - TRIP_LOAD_STARTED) * 1440))) Diff
FROM GATE2GATE_ACTIVITY_VW
WHERE TRIP_LOAD_STARTED >= to_date('01/FEB/2014','dd/MON-YYYY')
AND TRIP_LOAD_ENDED < to_date('03/FEB/2014','dd/MON-YYYY')
GROUP BY trunc(TRIP_LOAD_STARTED), trunc(TRIP_LOAD_ENDED)
Always post the sample create table and insert statements to verify the results and use to_date function with date format.
Message was edited by: Moazzam
-
try this:
select trunc(start_date),average(time_diff)
from table name
where trunc(startdate) = trunc(to_date('19-MAY-2014','DD-MON-YYYY')) -- remove time portion for grouping
group by trunc(start_date)
-
First of all alter your date format
ALTER SESSION SET NLS_DATE_FORMAT='DD/MM/YYYY HH24:MI:SS';
Then Run your Query.
Post your query Output.
Because you are calculating on Minutes This will give more insight to your data to provide a solution,
-
Thanks Moazzam that is what I needed.
hamidch