[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

sql avg

Posted on 2011-05-13
3
Medium Priority
?
531 Views
Last Modified: 2012-05-11

I have a database table that has 2  columns. defined as datetime, length of 8.
the column/data looks like :

tir_start - 1/1/1900 2:38:52 PM
tir_end - 1/1/1900 2:39:37 PM


there are many rows per day..the day date is another column.

I need to determine the avg time between the start and end column for many rows.  

0
Comment
Question by:NJJoeG8GT
3 Comments
 
LVL 9

Assisted Solution

by:TonyReba
TonyReba earned 200 total points
ID: 35755001
First have calculated the date diff

DATEDIFF ( datepart , startdate , enddate )

Once you have that you can use the AVG function)
Avg (datediffcolumn)
0
 
LVL 9

Accepted Solution

by:
anillucky31 earned 1600 total points
ID: 35755068
SELECT AVG(DATEDIFF(s,tir_start,tir_end)) FROM  yourtable

this will give time difference in seconds and will average them.
0
 
LVL 32

Assisted Solution

by:Ephraim Wangoya
Ephraim Wangoya earned 200 total points
ID: 35755086
try
select daycolumn, TotalMinutes / count(*) [Average time]
from
(
  select daycolumn, SUM(DATEDIFF(MINUTE, tir_start, tir_end)) as TotalMinutes
  from table1
) A
group by daycolumn

Open in new window

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question