SQL STDEV Function

STDEV returns the standard deviation of the specified values.

STDEV ignores NULL values.

Use STDEV if the values represent a sample, .

Use STDEVP if the values represent the entire population, .

Example

#

This example returns the standard deviation of the sales.

SELECT STDEV(TotalAmount) AS 'Standard Deviation'
  FROM [Order]
Result:  1 record
Standard Deviation
1990.6139633244

Syntax

Syntax of the STDEV function.

STDEV(value)

value -- a number or numeric column.

More Examples

STDEV with GROUP BY

PRODUCT
Id
ProductName
SupplierId
UnitPrice
Package
IsDiscontinued
SUPPLIER
Id
CompanyName
ContactName
City
Country
Phone
Fax
Problem: List the standard deviation of the products by supplier.
SELECT S.CompanyName, 
       STDEV(UnitPrice) AS 'Price Standard Deviation'
  FROM Product P
  JOIN Supplier S ON S.Id = P.SupplierId
 GROUP BY S.CompanyName
Result:  29 records
CompanyName Price Standard Deviation
Aux joyeux ecclésiastiques 173.594714781297
Bigfoot Breweries 2.3094010767585
Cooperativa de Quesos 'Las Cabras' 12.0208152801713
Escargots Nouveaux NULL
Exotic Liquids 4.93288286231625

Note: A NULL value is returned when a supplier has fewer than 2 products.


You may also like



Guides


vsn 3.1