我有以下查询
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
返回以下内容:
828 1
856 1
883 1
910 1
如果它是所有行的组合平均值,我如何返回单个结果?
答案 0 :(得分:3)
SELECT AVG(val)
FROM floatTable
WHERE tagindex IN (828, 856, 883, 910)
AND DateAndTime > DATEADD(HH, -1, GETDATE())
AND DateAndTime < DATEADD(HH, -2, GETDATE())
答案 1 :(得分:0)
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