PERCENTILE_CONT (Transact-SQL)PERCENTILE_CONT (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
SQL ServerSQL Server の列値の連続型分散に基づく百分位数を計算します。Calculates a percentile based on a continuous distribution of the column value in SQL ServerSQL Server. 結果には値が挿入され、列内の特定の値と一致しない可能性があります。The result is interpolated and might not be equal to any of the specific values in the column.
Transact-SQL 構文表記規則 (Transact-SQL)
Transact-SQL Syntax Conventions (Transact-SQL)
構文Syntax
PERCENTILE_CONT ( numeric_literal )
WITHIN GROUP ( ORDER BY order_by_expression [ ASC | DESC ] )
OVER ( [ <partition_by_clause> ] )
注意
SQL Server 2014 以前の Transact-SQL 構文を確認するには、以前のバージョンのドキュメントを参照してください。To view Transact-SQL syntax for SQL Server 2014 and earlier, see Previous versions documentation.
引数Arguments
numeric_literalnumeric_literal
計算する百分位数です。The percentile to compute. 値は 0.0 ~ 1.0 で指定してください。The value must range between 0.0 and 1.0.
WITHIN GROUP ( ORDER BY order_by_expression [ ASC | DESC ] )WITHIN GROUP ( ORDER BY order_by_expression [ ASC | DESC ])
並べ替える数値の一覧を指定し、百分位数を計算します。Specifies a list of numeric values to sort and compute the percentile over. order_by_expression は 1 つだけ許可されます。Only one order_by_expression is allowed. 式は、真数型または概数型に評価される必要があります。他のデータ型は使用できません。The expression must evaluate to an exact or approximate numeric type, with no other data types allowed. 真数型には、int、bigint、smallint、tinyint、numeric、bit、decimal、smallmoney、money があります。Exact numeric types are int, bigint, smallint, tinyint, numeric, bit, decimal, smallmoney, and money. 概数型は float と real です。Approximate numeric types are float and real. 既定の並べ替え順は昇順です。The default sort order is ascending.
OVER ( <partition_by_clause> )OVER ( <partition_by_clause> )
FROM 句で生成された結果セットをパーティションに分割します。このパーティションにパーセンタイル関数が適用されます。Divides the result set produced by the FROM clause into partitions to which the percentile function is applied. 詳細については、を参照してください。 OVER 句 (Transact-SQL).For more information, see OVER Clause (Transact-SQL). OVER 構文の <ORDER BY clause> と <rows or range clause> は、PERCENTILE_CONT 関数では指定できません。The <ORDER BY clause> and <rows or range clause> of the OVER syntax can't be specified in a PERCENTILE_CONT function.
戻り値の型Return Types
float(53)float(53)
互換性サポートCompatibility Support
互換性レベル 110 以上では、WITHIN GROUP は予約されたキーワードです。Under compatibility level 110 and higher, WITHIN GROUP is a reserved keyword. 詳細については、「ALTER DATABASE 互換性レベル (Transact-SQL)」を参照してください。For more information, see ALTER DATABASE Compatibility Level (Transact-SQL).
全般的な解説General Remarks
データセット内の NULL はすべて無視されます。Any nulls in the data set are ignored.
PERCENTILE_CONT は非決定的です。PERCENTILE_CONT is nondeterministic. 詳細については、「 決定的関数と非決定的関数」を参照してください。For more information, see Deterministic and Nondeterministic Functions.
例Examples
A.A. 基本構文例Basic syntax example
次の例では、PERCENTILE_CONT と PERCENTILE_DISC を使用して、各部門の従業員給与の中央値を検索します。The following example uses PERCENTILE_CONT and PERCENTILE_DISC to find the median employee salary in each department. これらの関数は同じ値を返さない可能性があります。These functions may not return the same value. PERCENTILE_CONT ではデータセットに存在するかどうかに関係なく適切な値が挿入され、PERCENTILE_DISC では常にセットから実際の値を返します。PERCENTILE_CONT interpolates the appropriate value, which may or may not exist in the data set, while PERCENTILE_DISC always returns an actual value from the set.
USE AdventureWorks2012;
SELECT DISTINCT Name AS DepartmentName
,PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY ph.Rate)
OVER (PARTITION BY Name) AS MedianCont
,PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY ph.Rate)
OVER (PARTITION BY Name) AS MedianDisc
FROM HumanResources.Department AS d
INNER JOIN HumanResources.EmployeeDepartmentHistory AS dh
ON dh.DepartmentID = d.DepartmentID
INNER JOIN HumanResources.EmployeePayHistory AS ph
ON ph.BusinessEntityID = dh.BusinessEntityID
WHERE dh.EndDate IS NULL;
次に結果セットの一部を示します。Here is a partial result set.
DepartmentName MedianCont MedianDisc
-------------------- ---------- ----------
Document Control 16.8269 16.8269
Engineering 34.375 32.6923
Executive 54.32695 48.5577
Human Resources 17.427850 16.5865
B.B. 基本構文例Basic syntax example
次の例では、PERCENTILE_CONT と PERCENTILE_DISC を使用して、各部門の従業員給与の中央値を検索します。The following example uses PERCENTILE_CONT and PERCENTILE_DISC to find the median employee salary in each department. これらの関数は同じ値を返さない可能性があります。These functions may not return the same value. PERCENTILE_CONT ではデータセットに存在するかどうかに関係なく適切な値が挿入され、PERCENTILE_DISC では常にセットから実際の値を返します。PERCENTILE_CONT interpolates the appropriate value, which may or may not exist in the data set, while PERCENTILE_DISC always returns an actual value from the set.
-- Uses AdventureWorks
SELECT DISTINCT DepartmentName
,PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY BaseRate)
OVER (PARTITION BY DepartmentName) AS MedianCont
,PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY BaseRate)
OVER (PARTITION BY DepartmentName) AS MedianDisc
FROM dbo.DimEmployee;
次に結果セットの一部を示します。Here is a partial result set.
DepartmentName MedianCont MedianDisc
-------------------- ---------- ----------
Document Control 16.826900 16.8269
Engineering 34.375000 32.6923
Human Resources 17.427850 16.5865
Shipping and Receiving 9.250000 9.0000
参照See Also
PERCENTILE_DISC (Transact-SQL)PERCENTILE_DISC (Transact-SQL)