// aggregates reference

SQL VAR_POP function

Population variance: divides by n and treats the group as the whole population.

類別
Aggregates
Returns
numeric
In this category
24 of 52

語法

VAR_POP(x) | VARP(x)

引擎支援

引擎Support備註
SQL Server Different name or syntax VARP 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)
Oracle 是 Supported under this name.

範例

PostgreSQL

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

SQL Server

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

小知識

  • One non-NULL value returns 0, unlike VAR_SAMP's NULL, because the divisor is n.
  • NULLs are excluded before the count.
  • MySQL's plain VARIANCE() is this function, not the sample one: a classic porting surprise.

Questions about VAR_POP

VAR_POP vs VAR_SAMP?

Divisor n versus n-1, and a single row yields 0 versus NULL.

What is VAR_POP in SQL Server?

VARP.

Why does MySQL's VARIANCE differ?

MySQL aliases VARIANCE to VAR_POP; PostgreSQL aliases it to VAR_SAMP. Always spell the variant you mean.

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.