STDEVP (Transact-SQL)STDEVP (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 standard deviation for the population for all values in the specified expression.
Transact-SQL 構文表記規則
Transact-SQL Syntax Conventions
構文Syntax
-- Aggregate Function Syntax
STDEVP ( [ ALL | DISTINCT ] expression )
-- Analytic Function Syntax
STDEVP ([ 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
数値式を指定します。Is a numeric expression. 集計関数とサブクエリは使用できません。Aggregate functions and subqueries are not permitted. expression は、bit データ型を除く、真数データ型または概数データ型の式です。expression is an expression of the exact numeric or approximate numeric data type category, except for the bit data type.
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 ステートメントの中のすべての項目に対して STDEVP を使用すると、結果セット内のすべての値が計算に含まれます。If STDEVP is used on all items in a SELECT statement, each value in the result set is included in the calculation. STDEVP は、数値型列に対して使用できます。STDEVP can be used with numeric columns only. NULL 値は無視されます。Null values are ignored.
STDEVP は、OVER 句や ORDER BY 句なしで使用される場合は決定的関数です。STDEVP 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: STDEVP を使用するA: Using STDEVP
この例では、AdventureWorks2012AdventureWorks2012 データベースの SalesPerson
テーブル内のすべてのボーナス額を母集団として標準偏差を返します。The following example returns the standard deviation for the population for all bonus values in the SalesPerson
table in the AdventureWorks2012AdventureWorks2012 database.
SELECT STDEVP(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: STDEVP を使用するB: Using STDEVP
次の例は、テーブル dbo.FactSalesQuota
の販売ノルマの値の STDEVP
を返します。The following example returns the STDEVP
of the sales quota values in the table dbo.FactSalesQuota
. 最初の列にはすべての個別値の標準偏差が含まれ、2 番目の列には重複値を含むすべての値の標準偏差が含まれます。The first column contains the standard deviation of all distinct values and the second column contains the standard deviation of all values including any duplicates values.
-- Uses AdventureWorks
SELECT STDEVP(DISTINCT SalesAmountQuota)AS Distinct_Values, STDEVP(SalesAmountQuota) AS All_Values
FROM dbo.FactSalesQuota;SELECT STDEVP(DISTINCT Quantity)AS Distinct_Values, STDEVP(Quantity) AS All_Values
FROM ProductInventory;
結果セットは次のようになります。Here is the result set.
Distinct_Values All_Values
---------------- ----------------
397676.79 397226.44
C.C. OVER で STDEVP を使用するUsing STDEVP with OVER
次の例は、暦年の各四半期に対する販売ノルマの値の STDEVP
を返します。The following example returns the STDEVP
of the sales quota values for each quarter in a calendar year. ORDER BY
句の OVER
によって STDEVP
が順序付けされ、ORDER BY
ステートメントの SELECT
によって結果セットが順序付けされることに注目してください。Notice that the ORDER BY
in the OVER
clause orders the STDEVP
and the ORDER BY
of the SELECT
statement orders the result set.
-- Uses AdventureWorks
SELECT CalendarYear AS Year, CalendarQuarter AS Quarter, SalesAmountQuota AS SalesQuota,
STDEVP(SalesAmountQuota) OVER (ORDER BY CalendarYear, CalendarQuarter) AS StdDeviation
FROM dbo.FactSalesQuota
WHERE EmployeeKey = 272 AND CalendarYear = 2002
ORDER BY CalendarQuarter;
結果セットは次のようになります。Here is the result set.
Year Quarter SalesQuota StdDeviation
---- ------- ---------------------- -------------------
2002 1 91000.0000 0.00
2002 2 140000.0000 24500.00
2002 3 70000.0000 29329.55
2002 4 154000.0000 34426.55
参照See Also
集計関数 (Transact-SQL) Aggregate Functions (Transact-SQL)
OVER 句 (Transact-SQL)OVER Clause (Transact-SQL)