我现在坚持使用postgres的计算中位数,因为postgres中没有关于计算中位数的函数。以下是我的查询,我想获得该查询的中值。请帮我怎么做。
SELECT count, conversion, company_id FROM (SELECT count(ap.id),
(count(ap.id)/cast(NULLIF(SUM(j.views), 0) as float) * 100) AS conversion,
j.company_id FROM applications ap RIGHT JOIN jobs j ON ap.job_id = j.id GROUP BY j.company_id order by conversion) with_avg
答案 0 :(得分:4)
有一个计算中位数的功能。中位数是百分之五十,您可以使用percentile_disc,我认为:https://www.postgresql.org/docs/9.6/static/functions-aggregate.html