Aggregate. Computes the standard deviation of a population consisting of a numeric-expression, as a DOUBLE.
STDDEV_POP( numeric-expression )
| numeric-expression | The expression whose population-based standard deviation is calculated over a set of rows. The expression is commonly a column name. |
s = [ (1/N) * SUM( xi - MEAN( x ) )2 ]1/2This standard deviation does not include rows where numeric-expression is NULL. It returns NULL for a group containing no rows.
SQL/2003 SQL foundation feature (T621) outside of core SQL.
-- create input stream schema
CREATE SCHEMA InSchema (
id STRING,
x FLOAT,
y FLOAT
);
-- create output stream schema
CREATE SCHEMA OutSchema (
id STRING,
x FLOAT,
y FLOAT,
stddev_pop_result FLOAT,
);
-- create input stream
CREATE INPUT STREAM StreamIn
SCHEMA InSchema;
-- create master window
CREATE MASTER WINDOW ResultWindow
SCHEMA OutSchema
KEEP 5 ROWS
;
-- create output stream
CREATE OUTPUT STREAM StreamOut
SCHEMA OutSchema;
-- input stream read data from csv file by ReadFromCsvFileAdapterType adapter
ATTACH INPUT ADAPTER ReadFromCSVFile TYPE ReadFromCsvFileAdapterType
TO STREAM StreamIn
PROPERTIES
FILENAME = "$ProjectFolder\..\data\data.csv",
TITLEROW = "false",
TIMESTAMPCOLUMN = "false",
RATE = "1",
USECURRENTTIMESTAMP = "true"
;
-- output stream write data to csv file by WriteToCsvFileAdapterType adapter
ATTACH OUTPUT ADAPTER WriteToCSVFile TYPE WriteToCsvFileAdapterType
TO STREAM StreamOut
PROPERTIES
FILENAME = "$ProjectFolder\..\data\result.csv"
;
-- insert the calculated result to window
INSERT INTO ResultWindow
SELECT id,x,y,
stddev_pop(x)
FROM StreamIn
KEEP 5 ROWS;
INSERT INTO StreamOut
SELECT *
FROM ResultWindow;