Reference > Functions > Aggregate
StDev
- 2005
- 2008
- 2012
- 2014
- 2016
- 2017
- 2019
- 2022
- 2005, 2008, 2012, 2014, 2016, 2017, 2019, 2022
StDev (Standard Deviation) Aggregate Function
Use the StDev
function to return the statistical standard deviation for all values in the specified expression.
Syntax
db.fx.StDev({expression})[.Distinct()]
Arguments
- expression
- – The field expression, composite element, or function result to use in calculating the standard deviation.
- Distinct()
- – Each unique value is considered while calculating the standard deviation for the population.
Returns
float
Examples
Select Statement
Select the standard deviation of product shipping weights.
float result = db.SelectOne(
db.fx.StDev(dbo.Product.ShippingWeight)
)
.From(dbo.Product)
.Execute();
Order By Clause
Select the standard deviation of product shipping weights ordered by the standard deviation of product shipping weights descending.
float result = db.SelectOne(
db.fx.StDev(dbo.Product.ShippingWeight)
)
.From(dbo.Product)
.OrderBy(db.fx.StDev(dbo.Product.ShippingWeight).Desc())
.Execute();
Having Clause
Select the product categories of all products, grouped by product category type having standard deviation greater than 1.
IEnumerable<ProductCategoryType?> results = db.SelectMany(
dbo.Product.ProductCategoryType
)
.From(dbo.Product)
.GroupBy(dbo.Product.ProductCategoryType)
.Having(db.fx.StDev(dbo.Product.ShippingWeight) > 1)
.Execute();