Is there an easy and fast way to calculate the rank of a field in a database using Ruby on Rails? For example, if I have a math_scores table, and would like to find a given a MathScore.find(:all, :condtions => ... :order =>...) then iterate through all of them to find out where the test score falls, but there's got to be a more straightforward way... Any advice?
Here's some info on the schema, it's just a simple table:
first_name varchar(50)
last_name varchar(50)
test_id int
score float
Clarification: I guess by question is closer to how would I retrieve the rank value when doing: rank = MathScore.find_by_sql("select count(*) as rank from (select * from math_scores where score > (select score from high_scores where test_id = 33 AND first_name = 'John' AND last_name = 'Doe') order by score desc) as s")
I get [#<HighScore:0x6ca4724 @attributes={"rank"=>"3"}>]:Array
based upon the query, but how do I get at the rank value?
Thanks in advance, Ben