Skip to content

Qt_script_stddev

Paweł Salawa edited this page Jun 29, 2019 · 4 revisions

Definition

Language: Qt Script
Plugin for language: ScriptingQt
How to use: Create custom SQL function, set it to "aggregate" type. Suggested name: stddev
Function arguments Keep undefined
Function usage: SELECT stddev(colName) from tableName
Description: SQLite offers an "Average" function, but no "Standard Deviation" function. This is easy to build using the Function Editor as an "Aggregate Function" by the name of StdDev.
Author: JrgMyr

Code

Initialization code:

n=0;
summe=0.0;
quadrate=0.0;

Per step code:

n++;
summe = summe + arguments[0];
quadrate = quadrate + (arguments[0] * arguments[0]);

Final step code:

return Math.sqrt(quadrate / n - (summe / n * summe / n));