I have the following query
SELECT tagindex, AVG(val) from floatTable
开发者_StackOverflow社区 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?
SELECT AVG(val)
FROM floatTable
WHERE tagindex IN (828, 856, 883, 910)
AND DateAndTime > DATEADD(HH, -1, GETDATE())
AND DateAndTime < DATEADD(HH, -2, GETDATE())
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
精彩评论