Var、VarP 函数 (Microsoft Access SQL)

适用于:Access 2013 | Access 2016

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

语法

Var (expr)

VarP (expr)

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

备注

VarP 函数计算样本总体,Var 函数计算样本总体抽样。

如果基础查询中包含了两个以下个记录,那么 VarVarP 函数返回 Null 值,这表示无法计算方差。

在查询表达式或 SQL 语句中使用 VarVarP 函数。

示例

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

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

Sub VarX() 
 
    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 variance of freight costs for  
    ' orders shipped to the United Kingdom.
    Set rst = dbs.OpenRecordset("SELECT " _ 
        & "Var(Freight) " _ 
        & "AS [UK Freight Variance] " _ 
        & "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, 20 
     
    Debug.Print 
     
    Set rst = dbs.OpenRecordset("SELECT " _ 
        & "VarP(Freight) " _ 
        & "AS [UK Freight VarianceP] " _ 
        & "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, 20 
 
    dbs.Close 
 
End Sub 

另请参阅

支持和反馈

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