Yes, the over partition by
means that it will not work with group by
. So remove it:
SELECT ScriptName, BranchName,
AVG(Passes) AS AvgPasses
FROM temp3
GROUP BY ScriptName, BranchName;
Technically, the reason is because Passes
is not in the group by
and not in an aggregation function.
First, if Passes
is an integer, the average will also be an integer. If you want a floating point average, then convert the value to the appropriate type.
Second, analytic functions do work with group by
. For instance, if you wanted the sum of all the averages, you could do:
SELECT ScriptName, BranchName,
AVG(Passes) AS AvgPasses,
SUM(AVG(Passes)) over (ScriptName, BranchName) as SumAvg
FROM temp3
GROUP BY ScriptName, BranchName;
Ok, that seems weird. But the min()
and max()
might be useful.