Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

283
Views
Postgres: promedio de valores superiores a los percentiles 90, 95 y 98

Tengo una columna en una tabla con varios registros enteros.

Necesito escribir una consulta PostgreSql que devolverá el promedio de todos los valores que son mayores que el percentil 90, 95 y 98.

p.ej

Tengo la serie 1-150 en mi columna.

Ahora, si tomo el percentil 90 de esta columna, es alrededor de 135.

Necesito calcular el promedio de todos los valores mayores a 135.

Del mismo modo para el percentil 95 y 98 también.

Y si es posible los tres valores en una sola consulta.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

como muestra utilizo números del 1 al 300:

 t=# select generate_series(1,300,1) g g --- 1 2 3 4 ...

aquí hay un ejemplo:

 t=# with p as ( with s as ( select generate_series(1,300,1) g ) select g,ntile(100) over (order by g) , case when ntile(100) over (order by g) between 90 and 94 then 90 when ntile(100) over (order by g) between 95 and 97 then 95 when ntile(100) over (order by g) >=98 then 98 end "percentile" from s ) select distinct "percentile",avg(g) over (partition by "percentile") from p where ntile >=90; percentile | avg ------------+---------------------- 90 | 275.0000000000000000 98 | 296.0000000000000000 95 | 287.0000000000000000 (3 rows)
over 4 years ago · Santiago Trujillo Report

0

Si entendí correctamente, puede ser que necesites esto.

tratar:

 with t(col) as( select * from generate_series(1, 150) ) select (select avg(col) from t where col > (select count(*) * 90 / 100.00 from t)), (select avg(col) from t where col > (select count(*) * 95 / 100.00 from t)), (select avg(col) from t where col > (select count(*) * 98 / 100.00 from t))
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!