Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Getting the average

Author  Topic 

tkotey
Yak Posting Veteran

75 Posts

Posted - 2013-02-23 : 08:31:18
Hello

How do I sum and get average of rows from this statement

--
SELECT DateDiff(dd,convert(datetime,invRecDate,103),convert(datetime,invToAdminPrepDT,103))-DateDiff(ww,convert(datetime,invRecDate,103),convert(datetime,invToAdminPrepDT,103))*2 AS Days FROM reportViewHQ WHERE invWorkshop = 'Fleet'
--

Thanks for your help

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-02-23 : 09:36:35
[code]SELECT
SUM(Days) AS SumofDays,
AVG(1.0*Days) AS AvgofDays
FROM
(
SELECT DateDiff(dd,convert(datetime,invRecDate,103),
convert(datetime,invToAdminPrepDT,103))-DateDiff(ww,convert(datetime,invRecDate,103),
convert(datetime,invToAdminPrepDT,103))*2 AS Days
FROM reportViewHQ
WHERE invWorkshop = 'Fleet'
) s[/code]
Go to Top of Page

tkotey
Yak Posting Veteran

75 Posts

Posted - 2013-02-23 : 10:04:56
Thanks Jams K for help.
Go to Top of Page
   

- Advertisement -