Assuming that my subquery
yields a number of rows with the columns (x,y), I would like to calculate the value avg(abs(x-mean)/y)
. where mean
effectively is avg(x)
.
select avg(abs(x-avg(x))/y) as incline from subquery
fails because I cannot nest aggregation functions. Nor can I think of a way to calculate the mean in a subquery while keeping the original result set. An avgdev function as it exists in other dialects would not exactly help me, so here I am stuck. Probably just due to lack of sql knowledge - calculating the value from the result set in postprocessing is easy.
Which SQL construct could help me?
Edit: Server version is 8.3.4. No window functions with WITH
or OVER
available here.