PostgreSQL百分位数_cont返回所有百分位数的相同值

PostgreSQL百分位数_cont返回所有百分位数的相同值,sql,postgresql,statistics,percentile,Sql,Postgresql,Statistics,Percentile,我试图从一些数据中提取百分位数,但每个百分位数的值都相同。为什么? SELECT three_sixty_review_aid, percentile_cont(0.95) within group (order by questions_combined asc) as p_95, percentile_cont(0.75) within group (order by questions_combined asc) as p_75, percentile_cont(0.5) within

我试图从一些数据中提取百分位数,但每个百分位数的值都相同。为什么?

SELECT three_sixty_review_aid, 
percentile_cont(0.95) within group (order by questions_combined asc) as p_95,
percentile_cont(0.75) within group (order by questions_combined asc) as p_75,
percentile_cont(0.5) within group (order by questions_combined asc) as p_50,
percentile_cont(0.25) within group (order by questions_combined asc) as p_25,
percentile_cont(0.1) within group (order by questions_combined asc) as p_10,
percentile_cont(0.05) within group (order by questions_combined asc) as p_05
FROM reviews_threesixty.peer_review_avg_combined_per_review
 group by three_sixty_review_aid

因为,对于由百分位控制列组成的每一行,应返回多行,如果使用GROUP BY,则所有百分位控制列将形成单行,前提是三个百分位控制列的review aid具有唯一的值。因此,如果三个“审阅”列具有唯一的值,则删除group by expression,以获得由百分比列组成的行的不同值:

SELECT  percentile_cont(0.95) within group (order by questions_combined asc) as p_95,
        percentile_cont(0.75) within group (order by questions_combined asc) as p_75,
        percentile_cont(0.5) within group (order by questions_combined asc) as p_50,
        percentile_cont(0.25) within group (order by questions_combined asc) as p_25,
        percentile_cont(0.1) within group (order by questions_combined asc) as p_10,
        percentile_cont(0.05) within group (order by questions_combined asc) as p_05
   FROM reviews_threesixty.peer_review_avg_combined_per_review;

如果删除另一列,会发生什么?因为你是按那个值分组的,我想你会得到所有不同的值。此外,Postgres不需要在此处添加OVER子句吗?我想这可能是SQL Server独有的。您好,谢谢您的回复,非常感谢。但是我现在得到了一个错误:语法错误达到或接近极限。非常奇怪,PostgreSQL 10。4@Letholdrus不客气,但我看不到字数限制。@Letholdrus我添加了一个演示。我根据您的原始答案将查询计划添加到了我的顶层question@Letholdrusthree\u Sixth\u review\u aid是唯一值的列吗?