Subject Re: [firebird-support] Re: Aggregate UDF?
Author Mark Rotteveel
> > > Actually, it can.
> > >
> > > STDDEV(x) = AVG(x^2) - (AVG(x))^2
> > >
> > > AVG can be calculated in one pass.
> >
> > Isn't it rather:
> >
> > STDDEV(x) = AVG( x^2 - (AVG(x))^2 )
> >
> > ?
>
> Nothing is like trying, and to me, PenWins suggestions seems OK - except
> that he forgot the square root.

Indeed, according to http://en.wikipedia.org/wiki/Standard_deviation#Identities_and_mathematical_properties ("Thus, the standard deviation is equal to the square root of (the average of the squares less the square of the average).")

> At least, the following produced a sensible
> result for my first (and only) test:
>
> with CTE(MySum) as
> (select avg(MyField*MyField)-(avg(MyField)*avg(MyField))
> from TEST_TABLE)
> select sqrt(MySum)
> from CTE
>
> So no need for any stored procedure,
> Set

--
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01