Search Postgresql Archives

Re: percentile rank query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Apr 10, 2008 at 4:36 PM, Osvaldo Rosario Kussama
<osvaldo.kussama@xxxxxxxxx> wrote:
>
>  Try:
>
>  SELECT count(*) AS frequency, score,
>  count((SELECT * FROM scoretable st2 WHERE st2.score <= st1.score)) AS
> runningtotal
>  FROM scoretable st1
>  GROUP BY score
>  ORDER BY score
>
>  Osvaldo
>

Thankyou Osvaldo- that worked!

Final version:

SELECT count(*) AS frequency, score,
((((SELECT count(uid) FROM scoretable st2 WHERE st2.score <=
st1.score) - count(*)) + (count(*)/2))::float/(select
count(*) from scoretable))

FROM scoretable st1
GROUP BY score
ORDER BY score

I think that's a percentile rank now.

Cheers

Will


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux