Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
udayfn12
Starting Member
15 Posts |
Posted - 2002-09-18 : 11:42:01
|
| Hi All,I am trying to find percentiles. I found the solution from this forum but the results have some inconsistencies when the data items have same values. This application is a migration project and my results are very close to existing application which is written in SAS / Cobol. The current solution I am using is select student , math, (( select count(*) from examresults b where a.math > b.math) + ((select count(*) from examresults c where a.math = c.math) * .5))/ (select count(*) from examresults) * 100 as percentilefrom examresults aOutput-------student math percentile ---------- ----------- ------------------------------ Lenny 2 25.000000000000Ralph 3 35.000000000000Joe 4 45.000000000000Mary 5 65.000000000000Frank 5 65.000000000000Susan 5 65.000000000000Bill 7 85.000000000000Ben 0 10.000000000000Fred 0 10.000000000000George 10 95.000000000000Output of the existing system27364563636381131390The existing system is calculating percentile Rank using the formula 100 * Rank / (Number of Defined Values + 1)Where Rank = the ratio's position after sorting all values from smallest (position = 1) to largest (position = the number of defined values)Note: The rank is a financial median when more than two rows has same value. (This is my problem (calculating median), if I use this formula).My table has around 50,000 rows and I have to calculate percentiles on 55 columns on each row.I would be grateful if any one could give me best solution. Thanks,Reddy.Please find the DDL statementscreate table ExamResults (Name varchar(10), math int);insert into ExamResults values ('Lenny',2); insert into ExamResults values ('Ralph',3); insert into ExamResults values ('Joe',4); insert into ExamResults values ('Mary',5); insert into ExamResults values ('Frank',5); insert into ExamResults values ('Susan',5); insert into ExamResults values ('Bill',7); insert into ExamResults values ('Ben',0); insert into ExamResults values ('Fred',0); insert into ExamResults values ('George',10); |
|
|
|
|
|
|
|