Explain ordered-set aggregates such as PERCENTILE_CONT and PERCENTILE_DISC with WITHIN GROUP. How do continuous and discrete percentiles differ?
Last updated
Ordered-set aggregates depend on input sort order, which is supplied with
WITHIN GROUP (ORDER BY col).PERCENTILE_CONTinterpolates between the nearest rows, so it may return a value not in the data (e.g. the true median for an even count).PERCENTILE_DISCreturns the first actual value whose cumulative distribution reaches the fraction. Use it when the result must be a real data point.