percentile_disc vs percentile_cont

PERCENTILE_DISC returns a value in your set/window, whereas PERCENTILE_CONT will interpolate;

In your query, when you use .72, PERCENTILE_CONT interpolates between 76 and 78, since 72% is neither one of them; PERCENTILE_DISC chooses 76 (the lowest of the ones)


I found this explanation very helpful http://mfzahirdba.blogspot.com/2012/09/difference-between-percentilecont-and.html

    ITEM REGION             WK FORECASTQTY
    ---- ---------- ---------- -----------
    TEST E                   3         137
    TEST E                   2         190
    TEST E                   1         232
    TEST E                   4         400



SELECT
   t.* ,
   PERCENTILE_CONT(0.5)
   WITHIN GROUP ( ORDER BY forecastqty)
   OVER (PARTITION BY ITEM , region ) AS PERCENTILE_CONT ,
   MEDIAN(forecastqty)
   OVER (PARTITION BY ITEM , region ) AS MEDIAN ,
   PERCENTILE_DISC(0.5)
   WITHIN GROUP ( ORDER BY forecastqty)
   OVER (PARTITION BY ITEM , region ) AS PERCENTILE_DISC
   FROM
   t ;



    ITEM REGION             WK FORECASTQTY PERCENTILE_CONT     MEDIAN PERCENTILE_DISC
    ---- ---------- ---------- ----------- --------------- ---------- ---------------
    TEST E                   3         137             211        211             190
    TEST E                   2         190             211        211             190
    TEST E                   1         232             211        211             190
    TEST E                   4         400             211        211             190

Tags:

Sql

Oracle

Plsql