Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql General > percentile rank...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 15244 of 17602
Post > Topic >>

percentile rank query

by willtemperley@[EMAIL PROTECTED] ("William Temperley") Apr 10, 2008 at 03:06 PM

Hi all

I'm trying to calculate the percentile rank for a record based on a
'score' column, e.g. a column of integers such as:
23,77,88,23,23,23,12,12,12,13,13,13
without using a stored procedure.

So,
select count(*) as frequency, score
from scoretable
group by score
order by score

Yields:

frequency score
3             12
3             13
4             23
1             77
1              88


However I'd like this result set:

frequency score   runningtotal
3             12        3
3             13        6
4             23        10
1             77        11
1              88       12

Where the running total is the previous frequency added to the current
frequency. Score order is significant.

So I can then do ((runningtotal-frequency)+(frequency/2))/(select
count(*) from scoretable) to give me the percentile rank for each
score.

Is this possible in one query? I just can't figure out how to get the
running total in a result set.

Thanks very much,

Will Temperley

-- 
Sent via pgsql-general mailing list (pgsql-general@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
 




 4 Posts in Topic:
percentile rank query
willtemperley@[EMAIL PROT  2008-04-10 15:06:18 
Re: percentile rank query
osvaldo.kussama@[EMAIL PR  2008-04-10 12:36:38 
Re: percentile rank query
willtemperley@[EMAIL PROT  2008-04-10 17:20:21 
Re: percentile rank query
sam@[EMAIL PROTECTED] (S  2008-04-10 19:38:00 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Dec 1 19:52:51 CST 2008.