Name
VAR_SAMP
Use VAR_SAMP to compute the sample variance of a set of values.
ANSI SQL Standard Syntax
VAR_SAMP(numeric_expression
)
MySQL and PostgreSQL
MySQL and PostgreSQL support the ANSI SQL syntax.
Oracle
Oracle supports the standard syntax. You may alternatively use the VARIANCE function, which differs from VAR_SAMP by returning zero (instead of NULL) for sets that contain only a single value.
Oracle also supports the following analytic syntax:
VAR_SAMP(numeric_expression
) OVER (window_clause
)
For an explanation of the window_clause
, see the section later in this chapter titled “ANSI SQL Window Functions.”
SQL Server
Use the VAR function.
Example
The following example computes the sample variance for the values 1, 2, and 3:
SELECT * FROM test;
X ---------- 1 2 3SELECT VAR_SAMP(x) FROM test;
VAR_SAMP(X) ----------- 1
Get SQL in a Nutshell, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.