PERCENTILE_CONT()
PERCENTILE_CONT() is a SQL function in the Window Functions category. Inverse distribution function: returns a value corresponding to the given percentile (linear interpolation). The syntax is PERCENTILE_CONT(fraction) WITHIN GROUP (ORDER BY column) OVER (PARTITION BY col). It accepts fraction. It returns percentile value. A typical example: SELECT department, PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY salary) AS median_salary FROM employees GROUP BY department; -- Median salary per department (the 50th percentile) SELECT department, PERCENTILE_CONT(0.25) WITHIN GROUP (ORDER BY salary) AS q1, PERCENTILE_CONT(0.75) WITHIN GROUP (ORDER BY salary) AS q3 FROM employees GROUP BY department; A close relative is ROW_NUMBER(), which assigns a unique sequential integer to each row within its partition (1, 2, 3...). A close relative is RANK(), which similar to ROW_NUMBER but gives the same rank to equal values. Leaves gaps in ranking. A close relative is DENSE_RANK(), which like RANK but without gaps. Equal values get the same rank, and the next number follows sequentially.