PERCENTILE_CONT Window Usage
PERCENTILE_CONT Window Usage is a SQL function in the Window Functions category. PERCENTILE_CONT as a window function computes percentile for each row within its partition. The syntax is PERCENTILE_CONT(fraction) WITHIN GROUP (ORDER BY col) OVER (PARTITION BY grp). It accepts fraction. It returns percentile window result. A typical example: SELECT department, name, salary, PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY salary) OVER (PARTITION BY department) AS dept_median, PERCENTILE_CONT(0.25) WITHIN GROUP (ORDER BY salary) OVER (PARTITION BY department) AS dept_q1, PERCENTILE_CONT(0.75) WITHIN GROUP (ORDER BY salary) OVER (PARTITION BY department) AS dept_q3 FROM employees; -- Each employee sees their departments median, Q1, Q3 -- Useful for comparing individual values to distribution 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.