Missing Functions: PERCENTILE_DISC, PERCENTILE_CONT & MEDIAN ...

This calculation will not work for x = 0, but you better use good old MIN instead of PERCENTILE_DISC(0).

-- SQL:2008 PERCENTILE_DISC aggregate function SELECT part_col ,PERCENTILE_DISC(x) WITHIN GROUP (ORDER BY data_col) --aggregate function FROM tab GROUP BY part_col; -- Teradata equivalent SELECT part_col ,data_col FROM tab QUALIFY ROW_NUMBER() OVER (PARTITION BY part_col ORDER BY data_col) = CAST(x * COUNT(*) OVER (PARTITION BY part_col) + 0.999999999999999 AS INT);

PERCENTILE_DISC is also defined as OLAP function adding the OVER clause. This requires moving the QUALIFY-condition into a CASE and another nested OLAP function:

-- SQL:2008 PERCENTILE_DISC OLAP function SELECT part_col ,data_col ,PERCENTILE_DISC(x) WITHIN GROUP (ORDER BY data_col) OVER (PARTITION BY part_col) FROM tab -- Teradata equivalent SELECT   part_col   ,data_col   ,MIN(pc) OVER (PARTITION BY part_col) AS PERCENTILE_DISC FROM  (   SELECT     part_col     ,data_col     ,CASE       WHEN ROW_NUMBER () OVER (PARTITION BY part_col ORDER BY data_col)          = CAST(COUNT(*) OVER (PARTITION BY part_col) * x + 0.999999999999999 AS INT)       THEN data_col     END AS pc   FROM tab  ) AS dt PERCENTILE_CONT

Whereas PERCENTILE_DISC returns one of the existing values, PERCENTILE_CONT is based on a linear interpolation between two consecutive values. First you calculate a hypothetical row number rn = (x * (n - 1)) + 1, where x is the percentile and n is the number of rows per group.


Sql And Percentile - Bookshelf

Pro Oracle SQL

Pro Oracle SQL

For example, computing the sales percentile of a retail outlet in a district ... In Listing 8-15, you calculate the top fifty sale percentile by year using ...

Oracle SQL and PL/SQL handbook, a guide for data administrators, developers, and business analysts

Oracle SQL and PL/SQL handbook, a guide for data administrators, developers, and business analysts

It has been called the inverse of percentile. It computes the position of a ... Listing 9.12 Using the CUMEJDIST Function SQL> select department_name, ...

Sql & Pl/Sql For Oracle 10G Black Book, 2007 Ed

Sql & Pl/Sql For Oracle 10G Black Book, 2007 Ed

... functions in SQL statement to cater to most of the requirements of data mining. ... Q Inverse percentile: The value in a data set that corresponds ...

SQL cookbook

SQL cookbook

The value returned is the value from the sorted rows that falls into the given percentile (in this case, 0.5, which is the middle because the boundary ...

SQL Clearly Explained

SQL Clearly Explained

For example, 0.9 returns the 90th percentile. Each function examines the percent rank of the values in a partition until it finds the one that is equal to ...

Casual Information Directory


Computing Percentiles in SQL Server - SQLTeam.com
According to the College Board, 570 falls into the 71st percentile. ... Weekly SQL Server newsletter with articles, forum posts, and blog posts via ...

Vol 1 #45 Percentile UDF s
SQL Server T-SQL User-Defined Function of the Week. Percentile in SQL Server ... Tommy is in the 75th percentile by height and the 55th percentile of weight for 6 year ...

Calculate Percentiles with SQL Server 2005
Learn one of the techniques for calculating percentiles with SQL Server 2005 using the new SQL Server Common Table Expression and the latest ROW_NUMBER function.

Calculating Percentile in SQL Server Analysis Services MDX
In this article, you'll learn how to use MDX to calculate percentile easily. ... Brian has spoken at conferences like PASS, SQL Connections and TechEd and many Code Camps. ...

Calculating percentiles in SQL
Enterprise and business performance management, E-Business Suite, Implementing and upgrading Oracle apps, ... We could get our percentiles with SQL like this: select a.*, round ...