Computes the statistical variance of a sample consisting of a numeric-expression, as a DOUBLE.
VAR_SAMP( numeric-expression )
VAR_SAMP( numeric-expression ) OVER ( window-spec )
window-spec : see Syntax 2 instructions in the Remarks section below
numeric-expression The expression whose sample-based variance is calculated over a set of rows. The expression is commonly a column name.
DOUBLE
This function converts its argument to DOUBLE, performs the computation in double-precision floating point, and returns a DOUBLE as the result.
The variance (s^{2}) of numeric-expression (x) is computed according to the following formula, which assumes a normal distribution:
s^{2} = (1/( N - 1 )) * SUM( x_{I} - mean( x ) )^{2}
This variance does not include rows where numeric-expression is NULL. It returns NULL for a group containing either 0 or 1 rows.
Syntax 2 represents usage as a window function in a SELECT statement. As such, elements of window-spec can be specified either in the function syntax (inline), or in conjunction with a WINDOW clause in the SELECT statement. See the window-spec definition provided in WINDOW clause.
For more information about using window functions in SELECT statements, including working examples, see Window functions.
SQL/2003 SQL foundation feature outside core SQL. The VARIANCE syntax is a vendor extension.
The following statement lists the average and variance in the number of items per order in different time periods:
SELECT YEAR( ShipDate ) AS Year, QUARTER( ShipDate ) AS Quarter, AVG( Quantity ) AS Average, VAR_SAMP( quantity ) AS Variance FROM SalesOrderItems GROUP BY Year, Quarter ORDER BY Year, Quarter; |
Year | Quarter | Average | Variance |
---|---|---|---|
2000 | 1 | 25.775148 | 205.1158... |
2000 | 2 | 27.050847 | 227.0939... |
... | ... | ... | ... |
Envoyer votre avis sur cette page par email. | Copyright © 2009, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.1 |