Skip to content

Instantly share code, notes, and snippets.

@rchardptrsn
Created April 17, 2022 16:30
Show Gist options
  • Save rchardptrsn/050f967a68ec3588ebcfd2dd899c7529 to your computer and use it in GitHub Desktop.
Save rchardptrsn/050f967a68ec3588ebcfd2dd899c7529 to your computer and use it in GitHub Desktop.
calculate percentiles in postgresql
SELECT
PERCENTILE_CONT(0.25) WITHIN GROUP(ORDER BY f.well_count) percentile25,
PERCENTILE_CONT(0.5) WITHIN GROUP(ORDER BY f.well_count) percentile50,
PERCENTILE_CONT(0.75) WITHIN GROUP(ORDER BY f.well_count) percentile75,
PERCENTILE_CONT(1.0) WITHIN GROUP(ORDER BY f.well_count) percentile100
FROM (
SELECT COUNT(county) well_count
FROM fracking
GROUP BY county
) f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment