Dofactory.com
Dofactory.com
Earn income with your data and sql skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

SQL VARP Function

VARP returns the statistical variance for the population of the given values.

This funcion ignores NULL values.

Use VARP if the given values represent the entire population.

Use VAR if the given values represent a sample.

Example

#

This example return the variance for the population of all sales.

SELECT VARP(TotalAmount) AS 'Variance'
  FROM [Order]
Result:  1 record
Variance
3957769.80164355

Syntax

Syntax of the VARP function.

VARP(value)

value -- a number or numeric column.

More Examples

VARP with GROUP BY

PRODUCT
Id
ProductName
SupplierId
UnitPrice
Package
IsDiscontinued
SUPPLIER
Id
CompanyName
ContactName
City
Country
Phone
Fax
Problem: List suppliers with the statistical variance for the population of their product prices.
SELECT S.CompanyName, 
       VARP(UnitPrice) AS 'Price Variance'
  FROM Product P
  JOIN Supplier S ON S.Id = P.SupplierId
 GROUP BY S.CompanyName
Result:  29 records
CompanyName Price Variance
Aux joyeux ecclésiastiques 15067.5625
Bigfoot Breweries 3.55555555555554
Cooperativa de Quesos 'Las Cabras' 72.25
Escargots Nouveaux 0
Exotic Liquids 16.2222222222222

Note: A value of 0 is returned when a supplier only has 1 product.


You may also like



Last updated on Dec 21, 2023

Earn income with your data and sql skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.