VARP (Transact-SQL)VARP (Transact-SQL)
適用対象:Applies to: SQL ServerSQL Server (サポートされているすべてのバージョン)
SQL ServerSQL Server (all supported versions)
Azure SQL データベースAzure SQL Database
Azure SQL データベースAzure SQL Database
Azure SQL Managed InstanceAzure SQL Managed Instance
Azure SQL Managed InstanceAzure SQL Managed Instance
Azure Synapse AnalyticsAzure Synapse Analytics
Azure Synapse AnalyticsAzure Synapse Analytics
Parallel Data WarehouseParallel Data Warehouse
Parallel Data WarehouseParallel Data Warehouse
SQL ServerSQL Server (サポートされているすべてのバージョン)
SQL ServerSQL Server (all supported versions)
Azure SQL データベースAzure SQL Database
Azure SQL データベースAzure SQL Database
Azure SQL Managed InstanceAzure SQL Managed Instance
Azure SQL Managed InstanceAzure SQL Managed Instance
Azure Synapse AnalyticsAzure Synapse Analytics
Azure Synapse AnalyticsAzure Synapse Analytics
Parallel Data WarehouseParallel Data Warehouse
Parallel Data WarehouseParallel Data Warehouse
指定した式のすべての値について、母集団に対する統計的変位を返します。Returns the statistical variance for the population for all values in the specified expression.
Transact-SQL 構文表記規則
Transact-SQL Syntax Conventions
構文Syntax
-- Aggregate Function Syntax
VARP ( [ ALL | DISTINCT ] expression )
-- Analytic Function Syntax
VARP ([ ALL ] expression) OVER ( [ partition_by_clause ] order_by_clause)
注意
SQL Server 2014 以前の Transact-SQL 構文を確認するには、以前のバージョンのドキュメントを参照してください。To view Transact-SQL syntax for SQL Server 2014 and earlier, see Previous versions documentation.
引数Arguments
ALLALL
すべての値にこの関数を適用します。Applies the function to all values. ALL が既定値です。ALL is the default.
DISTINCTDISTINCT
重複する値は 1 つだけカウントします。Specifies that each unique value is considered.
式 (expression)expression
bit データ型を除く、真数または概数データ型カテゴリの 式です。Is an expression of the exact numeric or approximate numeric data type category, except for the bit data type. 集計関数とサブクエリは使用できません。Aggregate functions and subqueries are not permitted.
OVER ( [ partition_by_clause ] order_by_clause )OVER ( [ partition_by_clause ] order_by_clause)
partition_by_clause は、FROM 句で生成された結果セットをパーティションに分割します。このパーティションに関数が適用されます。partition_by_clause divides the result set produced by the FROM clause into partitions to which the function is applied. 指定しない場合、関数ではクエリ結果セットのすべての行を 1 つのグループとして扱います。If not specified, the function treats all rows of the query result set as a single group. order_by_clause は、操作が実行される論理的順序を決定します。order_by_clause determines the logical order in which the operation is performed. order_by_clause は必須です。order_by_clause is required. 詳細については、を参照してください。 OVER 句 (Transact-SQL).For more information, see OVER Clause (Transact-SQL).
戻り値の型Return Types
floatfloat
注釈Remarks
SELECT ステートメントのすべてのアイテムで VARP を使用すると、結果セットの各値が計算に含められます。If VARP is used on all items in a SELECT statement, each value in the result set is included in the calculation. VARP は、数値型列に対して使用できます。VARP can be used with numeric columns only. NULL 値は無視されます。Null values are ignored.
VARP は、OVER 句や ORDER BY 句なしで使用される場合は決定的関数です。VARP is a deterministic function when used without the OVER and ORDER BY clauses. OVER 句や ORDER BY 句と共に使用される場合は、非決定的関数です。It is nondeterministic when specified with the OVER and ORDER BY clauses. 詳細については、「 決定的関数と非決定的関数」を参照してください。For more information, see Deterministic and Nondeterministic Functions.
例Examples
A: VARP を使用するA: Using VARP
この例では、AdventureWorks2012AdventureWorks2012 データベースの SalesPerson
テーブル内のすべてのボーナス額を母集団として偏差を返します。The following example returns the variance for the population for all bonus values in the SalesPerson
table in the AdventureWorks2012AdventureWorks2012 database.
SELECT VARP(Bonus)
FROM Sales.SalesPerson;
GO
例: Azure Synapse AnalyticsAzure Synapse Analytics、Parallel Data WarehouseParallel Data WarehouseExamples: Azure Synapse AnalyticsAzure Synapse Analytics and Parallel Data WarehouseParallel Data Warehouse
B: VARP を使用するB: Using VARP
次の例は、テーブル dbo.FactSalesQuota
の販売ノルマの値の VARP
を返します。The following example returns the VARP
of the sales quota values in the table dbo.FactSalesQuota
. 最初の列にはすべての個別値の分散が含まれ、2 番目の列には重複値を含むすべての値の分散が含まれます。The first column contains the variance of all distinct values and the second column contains the variance of all values including any duplicates values.
-- Uses AdventureWorks
SELECT VARP(DISTINCT SalesAmountQuota)AS Distinct_Values, VARP(SalesAmountQuota) AS All_Values
FROM dbo.FactSalesQuota;
結果セットは次のようになります。Here is the result set.
Distinct_Values All_Values
---------------- ----------------
158146830494.18 157788848582.94
C.C. OVER で VARP を使用するUsing VARP with OVER
次の例は、暦年の各四半期に対する販売ノルマの値の VARP
を返します。The following example returns the VARP
of the sales quota values for each quarter in a calendar year. OVER 句の ORDER BY は統計的分散を並べ替え、SELECT ステートメントの ORDER BY は結果セットを並べ替えることに注意してください。Notice that the ORDER BY in the OVER clause orders the statistical variance and the ORDER BY of the SELECT statement orders the result set.
-- Uses AdventureWorks
SELECT CalendarYear AS Year, CalendarQuarter AS Quarter, SalesAmountQuota AS SalesQuota,
VARP(SalesAmountQuota) OVER (ORDER BY CalendarYear, CalendarQuarter) AS Variance
FROM dbo.FactSalesQuota
WHERE EmployeeKey = 272 AND CalendarYear = 2002
ORDER BY CalendarQuarter;
結果セットは次のようになります。Here is the result set.
Year Quarter SalesQuota Variance
---- ------- ---------------------- -------------------
2002 1 91000.0000 0.00
2002 2 140000.0000 600250000.00
2002 3 70000.0000 860222222.22
2002 4 154000.0000 1185187500.00
参照See Also
集計関数 (Transact-SQL) Aggregate Functions (Transact-SQL)
OVER 句 (Transact-SQL)OVER Clause (Transact-SQL)