Subject Re: [firebird-support] Standard Deviation
Author Richard Wesley
On 29 Dec 2008, at 04:54, mielhostens wrote:

> Anybody who knows if there is a UDF or stored procedure to calculate
> the standard deviation of a variable column?

You can't create plug-in aggregators. For the common statistical
aggregators, you can use:

STDEV
(CASE WHEN COUNT(%1) > 1 THEN
SQRT((COUNT(%1) * SUM(POWER(%1,2)) - POWER(SUM(%1), 2) ) /
(COUNT(%1)*(COUNT(%1) - 1)))
ELSE CAST(NULL AS DOUBLE PRECISION) END)

STDEVP
(CASE WHEN COUNT(%1) > 0 THEN
SQRT((COUNT(%1) * SUM(POWER(%1,2)) - POWER(SUM(%1), 2) ) /
(POWER(COUNT(%1),2)))
ELSE CAST(NULL AS DOUBLE PRECISION) END)

VAR
(CASE WHEN COUNT(%1) > 1 THEN
((COUNT(%1) * SUM(POWER(%1,2)) - POWER(SUM(%1), 2) ) /
(COUNT(%1)*(COUNT(%1) - 1)))
ELSE CAST(NULL AS DOUBLE PRECISION) END)

VARP
(CASE WHEN COUNT(%1) > 0 THEN
((COUNT(%1) * SUM(POWER(%1,2)) - POWER(SUM(%1), 2) ) /
(POWER(COUNT(%1),2)))
ELSE CAST(NULL AS DOUBLE PRECISION) END)

HTH,
________________________________________________________
Richard Wesley Senior Software Developer Tableau
Software
Visit: http://www.trytableau.com/now.html