Created
June 3, 2017 12:06
-
-
Save mble/2a3e410c35b90b8da2a2d945a964d949 to your computer and use it in GitHub Desktop.
Calculating the min, median and max in PostgreSQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Small example demonstrating to calculate the median without using an custom built aggregate function | |
select | |
min(score) | |
-- percentile_cont is a function that returns a value corresponding to the specified fraction in the ordering, | |
-- interpolating between adjacent input items if needed. By setting the fraction to 0.5, this essentially works | |
-- as the median of the ordered set provided by the grouping. | |
, percentile_cont(0.5) with group (order by score) AS median | |
, max(score) | |
from result; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment