I currently have a query that works like so:
select AVG(t2 - t1) as delay,
percentile_cont(0.25) within group (order by (t2 - t1)) as q25,
percentile_cont(0.5) within group (order by (t2 - t1)) as median,
percentile_cont(0.75) within group (order by (t2 - t1)) as q75,
p.bool1,
p.cat1
from people p
group by p.bool1, p.cat1
order by p.cat1,p.bool1
However, I read on the postgres functions aggregation page: https://www.postgresql.org/docs/9.4/functions-aggregate.html
That I should be able to specify multiple quantiles:
percentile_cont(fractions) WITHIN GROUP (ORDER BY sort_expression) double precision[] double precision or interval array of sort expression's type multiple continuous percentile: returns an array of results matching the shape of the fractions parameter, with each non-null element replaced by the value corresponding to that percentile
I'd like to use this so I don't recalculate the t2 - t1 for every quantile. What's the right syntax to get multiple quantiles? Would I need a subquery?