This is the kind of query that kills some servers – ranking.
It’s a bit hard to make programmers understand how important the performance of their code can have a big impact on server speed – they all seems to think that throwing more hardware will solve all world’s problems… unfortunately it does not work that way.
So, after the app is completed and tested and validated by the manager (with a small data-set, of course), it goes live. After a few thousand records are inserted, things start to slow down, and it is exactly the report that the manager will look everyday. If this is familiar to you, take a look at the hints and techniques in this article: Nasty Fast PERCENT_RANK from SQL Server Central folks.
It’s not just the ranking itself, but all types of queries and data manipulation shown there that may help you. And the ideas work in all database engines, of course changing the language to the one you like.
and happy coding!