StDev、StDevP 函数 (Microsoft Access SQL)

适用于:Access 2013 | Access 2016

返回以包含在查询的指定字段内的一组值作为总体样本或总体样本抽样的标准偏差的估计值。

语法

StDev (expr)

StDevP (expr)

expr 占位符表示一个字符串表达式,该表达式标识包含要计算的数字数据的字段,或使用该字段中的数据执行计算的表达式。 expr 中的操作数可以包括表字段、常量或者函数(可以是固有函数或用户定义的函数,但不能是其他 SQL 聚合函数)的名称。

备注

StDevP 函数对总体样本进行计算,StDev 函数对总体样本抽样进行计算。

如果基础查询包含的记录少于两个(或者没有记录,对于 StDevP 函数),那么,这些函数将返回 Null 值(表示无法计算标准偏差)。

在查询表达式中使用 StDevStDevP 函数。 也可以将该表达式用于 QueryDef 对象的 SQL 属性中,或者在基于 SQL 查询创建 Recordset对象时使用该表达式。

示例

以下示例使用 Orders 表估算发往 United Kingdom 的订单的运货费的标准偏差。

以下示例调用 EnumFields 过程,您可以在 SELECT 语句示例中找到该过程。

Sub StDevX() 
 
    Dim dbs As Database, rst As Recordset 
 
    ' Modify this line to include the path to Northwind 
    ' on your computer. 
    Set dbs = OpenDatabase("Northwind.mdb") 
 
    ' Calculate the standard deviation of the freight 
    ' charges for orders shipped to the United Kingdom. 
    Set rst = dbs.OpenRecordset("SELECT " _ 
        & "StDev(Freight) " _ 
        & "AS [Freight Deviation] FROM Orders " _ 
        & "WHERE ShipCountry = 'UK';") 
 
    ' Populate the Recordset. 
    rst.MoveLast 
     
    ' Call EnumFields to print the contents of the  
    ' Recordset. Pass the Recordset object and desired 
    ' field width. 
    EnumFields rst, 15 
     
    Debug.Print 
     
    Set rst = dbs.OpenRecordset("SELECT " _ 
        & "StDevP(Freight) " _ 
        & "AS [Freight DevP] FROM Orders " _ 
        & "WHERE ShipCountry = 'UK';") 
 
    ' Populate the Recordset. 
    rst.MoveLast 
 
    ' Call EnumFields to print the contents of the  
    ' Recordset. Pass the Recordset object and desired 
    ' field width. 
    EnumFields rst, 15 
 
    dbs.Close 
 
End Sub 

另请参阅

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。