tags:

views:

32

answers:

2

I have the following query

SELECT tagindex, AVG(val) from floatTable
 WHERE tagindex IN(828,856,883,910)
   AND DateAndTime > DATEADD(HH,-1,GETDATE()) 
   AND DateAndTime < DATEADD(HH,-2,GETDATE())
group by tagindex

It returns the following:

828   1
856   1
883   1
910   1

How can I return a single result where it is the combined average of all the rows?

A: 
Select Avg(AverageValue)
From
(
   SELECT tagindex, AVG(val) as AverageValue from floatTable
   WHERE tagindex IN(828,856,883,910)
   AND DateAndTime > DATEADD(HH,-1,GETDATE()) AND DateAndTime < DATEADD(HH,-2,GETDATE())
   group by tagindex
) AverageValues
Jeremy
+3  A: 
SELECT AVG(val) 
FROM floatTable 
WHERE tagindex IN (828, 856, 883, 910) 
    AND DateAndTime > DATEADD(HH, -1, GETDATE()) 
    AND DateAndTime < DATEADD(HH, -2, GETDATE()) 
RedFilter