尝试在对filter()
的调用中使用percentile_const
子句,但不确定是否可以这样做。有办法吗?这是查询示例:
select
count(*) as n1,
count(*) filter(where ha >= 0) as n2,
percentile_cont(.9) within group (order by es asc) as p1,
percentile_cont(.9) filter (where ha >= 0) within group (order by es asc) as p2
from mytable where mypid = 123;
该查询在没有p2
调用的情况下仍然可以正常工作,但是您可以看到我想做什么。
答案 0 :(得分:1)
filter
必须放在within group
部分之后:
select
count(*) as n1,
count(*) filter(where ha >= 0) as n2,
percentile_cont(.9) within group (order by es asc) as p1,
percentile_cont(.9) within group (order by es asc) filter (where ha >= 0) as p2
from mytable
where mypid = 123;