sql avg

Posted on 2011-05-13
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.  

Question by:NJJoeG8GT
    LVL 9

    Assisted Solution

    First have calculated the date diff

    DATEDIFF ( datepart , startdate , enddate )

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

    Accepted Solution

    SELECT AVG(DATEDIFF(s,tir_start,tir_end)) FROM  yourtable

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

    Assisted Solution

    select daycolumn, TotalMinutes / count(*) [Average time]
      select daycolumn, SUM(DATEDIFF(MINUTE, tir_start, tir_end)) as TotalMinutes
      from table1
    ) A
    group by daycolumn

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
    Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
    Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
    Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now