Percentile Discrete Median Per Group
Compute the exact median per group using the percentile_disc window function with a 0.5 fraction parameter.
Code
SELECT DISTINCT
department,
PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY salary)
OVER (PARTITION BY department) AS median_salary
FROM employees
ORDER BY department;Report a problem with this exampleOpens a pre-filled issue on GitHub.