Quantcast
Channel: Programming Tips – Black Belt Review
Viewing all articles
Browse latest Browse all 16

SQL Server Statistical Functions – VAR, VARP, STDEV, STDEVP

$
0
0

SQL Server offers the following statistical functions.

VAR Returns the statistical variance of all values in the specified expression.
VARP Returns the statistical variance for the population for all values in the specified expression
STDEV Returns the statistical standard deviation of all values in the specified expression
STDEVP Returns the statistical standard deviation for the population for all values in the specified expression

All these functions return float.

The OVER clause may follow all aggregate functions except CHECKSUM.

Here is another sample to explain the relationships between SQL Server statistic functions:

USE AdventureWorks;
GO

SELECT
  STDEVP(Bonus)
  ‘Standard Deviation for the Population’,

  STDEV(Bonus)
  ‘Standard Deviation’,

  VAR(Bonus)
  ‘Variance’,

  STDEV(Bonus) * STDEV(Bonus)
  ‘VAR via STDEV’,

  VARP(Bonus)
  ‘Variance for the Population’,

  STDEVP(Bonus) * STDEVP(Bonus)
  ‘VARP via STDEVP’,

  VAR(Bonus) * (COUNT(Bonus)-1) / COUNT(Bonus)
  ‘VARP via VAR‘

FROM Sales.SalesPerson;
GO


Viewing all articles
Browse latest Browse all 16

Trending Articles