// aggregates reference

SQL VAR_SAMP function

Sample variance: divides by n-1 and needs at least two non-NULL values.

카테고리
Aggregates
Returns
numeric
In this category
23 of 52

구문

VAR_SAMP(x) | VAR(x)

엔진 지원

엔진Support메모
SQL Server Different name or syntax VAR is the SQL Server spelling
PostgreSQL 예 Supported under this name.
MySQL 예 Supported under this name.
SQLite Not built in not built in; use an extension or SUM((x-avg)*(x-avg))/(COUNT(x)-1)
Oracle 예 Supported under this name.

예시

PostgreSQL

SELECT var_samp(price) FROM products WHERE category_id = 7;

SQL Server

SELECT VAR(price) FROM products WHERE category_id = 7;

알아 두면 좋은 정보

  • One non-NULL value returns NULL; two or more divide by count-1.
  • NULLs are skipped, so the denominator counts only present values.
  • In SQLite the whole family is missing; an extension or a manual SUM((x-avg)*(x-avg))/(COUNT(x)-1) formula fills the gap.

Questions about VAR_SAMP

VAR_SAMP vs VAR_POP?

The divisor: n-1 versus n, and the one-row result: NULL versus 0.

What is VAR_SAMP in SQL Server?

VAR.

How do I get standard deviation from it?

Take the square root, or call STDDEV_SAMP directly.

Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.

Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, Oracle.

// fewer lookups

Functions your engine actually has

SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.